diff options
| author | Edward Barnard | 2017-04-19 09:31:26 +0100 | 
|---|---|---|
| committer | Edward Barnard | 2017-04-19 09:31:26 +0100 | 
| commit | 7079d594fa45495b411949d65d1d3a8f5dfecdcd (patch) | |
| tree | ae500b3fd6453b76ff3a85593ecd429f8d2ba27e | |
| parent | 1df5db005ea9959c4e19107997f446dc17095be4 (diff) | |
| download | rust-plist-7079d594fa45495b411949d65d1d3a8f5dfecdcd.tar.bz2 | |
Fix reading small binary plists with data stored in the 6 byte trailer padding. Closes #20.v0.1.3
| -rw-r--r-- | src/binary/reader.rs | 2 | ||||
| -rw-r--r-- | tests/fuzzer.rs | 22 | 
2 files changed, 19 insertions, 5 deletions
| diff --git a/src/binary/reader.rs b/src/binary/reader.rs index 770b12f..d9bf667 100644 --- a/src/binary/reader.rs +++ b/src/binary/reader.rs @@ -93,7 +93,7 @@ impl<R: Read + Seek> EventReader<R> {          // File size minus trailer and header          // Truncated to max(usize) -        self.max_allocation = trailer_start.saturating_sub(6 + 8) as usize; +        self.max_allocation = trailer_start.saturating_sub(8) as usize;          // Read offset table          try!(self.reader.seek(SeekFrom::Start(offset_table_offset))); diff --git a/tests/fuzzer.rs b/tests/fuzzer.rs index 65ce8eb..827b8c5 100644 --- a/tests/fuzzer.rs +++ b/tests/fuzzer.rs @@ -1,7 +1,7 @@  extern crate plist;  use std::io::Cursor; -use plist::Plist; +use plist::{Plist, Result};  #[test]  fn too_large_allocation() { @@ -27,8 +27,22 @@ fn binary_circular_reference() {      test_fuzzer_data_err(data);  } -fn test_fuzzer_data_err(data: &[u8]) { +// Issue 20 - not found by fuzzing but this is a convenient place to put the test. +#[test] +fn binary_with_data_in_trailer() { +    let data = b"bplist00\xd0\x08\0\0\0\0\0\0\x01\x01\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\t"; +    test_fuzzer_data_ok(data); +} + +fn test_fuzzer_data(data: &[u8]) -> Result<Plist> {      let cursor = Cursor::new(data); -    let res = Plist::read(cursor); -    assert!(res.is_err()); +    Plist::read(cursor) +} + +fn test_fuzzer_data_ok(data: &[u8]) { +    assert!(test_fuzzer_data(data).is_ok()); +} + +fn test_fuzzer_data_err(data: &[u8]) { +    assert!(test_fuzzer_data(data).is_err());  } | 
