From 62977a504825f12126aa53c3d5cd8affc95c4a7c Mon Sep 17 00:00:00 2001 From: Edward Barnard Date: Sun, 5 Mar 2017 12:00:00 +0000 Subject: Handle max_allocation correctly for files over 4GB. --- src/binary/reader.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/binary/reader.rs') 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 { 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 EventReader { @@ -56,13 +56,12 @@ impl EventReader { fn can_allocate(&self, len: u64) -> bool { let byte_len = len.saturating_mul(mem::size_of::() as u64); - byte_len <= self.max_allocation + byte_len <= self.max_allocation as u64 } fn allocate_vec(&self, len: u64) -> Result> { if self.can_allocate::(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 EventReader { let offset_table_offset = try!(self.reader.read_u64::()); // 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))); -- cgit v1.2.3