diff options
| author | Edward Barnard | 2017-03-05 12:00:00 +0000 | 
|---|---|---|
| committer | Edward Barnard | 2017-03-05 12:00:00 +0000 | 
| commit | 62977a504825f12126aa53c3d5cd8affc95c4a7c (patch) | |
| tree | e685b37ef60cd804aaecae3cdf6180f3ff2ac131 | |
| parent | eaf7808bc563b281aadd412b6f868d4c8124b43c (diff) | |
| download | rust-plist-62977a504825f12126aa53c3d5cd8affc95c4a7c.tar.bz2 | |
Handle max_allocation correctly for files over 4GB.
| -rw-r--r-- | src/binary/reader.rs | 10 | 
1 files changed, 5 insertions, 5 deletions
| diff --git a/src/binary/reader.rs b/src/binary/reader.rs index 474e69d..e8a2bf8 100644 --- a/src/binary/reader.rs +++ b/src/binary/reader.rs @@ -39,7 +39,7 @@ pub struct EventReader<R> {      finished: bool,      // The largest single allocation allowed for this Plist.      // Equal to the number of bytes in the Plist minus the magic and trailer. -    max_allocation: u64, +    max_allocation: usize,  }  impl<R: Read + Seek> EventReader<R> { @@ -56,13 +56,12 @@ impl<R: Read + Seek> EventReader<R> {      fn can_allocate<T>(&self, len: u64) -> bool {          let byte_len = len.saturating_mul(mem::size_of::<T>() as u64); -        byte_len <= self.max_allocation +        byte_len <= self.max_allocation as u64      }      fn allocate_vec<T>(&self, len: u64) -> Result<Vec<T>> {          if self.can_allocate::<T>(len) { -            let len = u64_to_usize(len)?; -            Ok(Vec::with_capacity(len)) +            Ok(Vec::with_capacity(len as usize))          } else {              Err(Error::InvalidData)          } @@ -86,7 +85,8 @@ impl<R: Read + Seek> EventReader<R> {          let offset_table_offset = try!(self.reader.read_u64::<BigEndian>());          // File size minus trailer and header -        self.max_allocation = trailer_start.saturating_sub(6 + 8); +        // Truncated to max(usize) +        self.max_allocation = trailer_start.saturating_sub(6 + 8) as usize;          // Read offset table          try!(self.reader.seek(SeekFrom::Start(offset_table_offset))); | 
