aboutsummaryrefslogtreecommitdiffstats
path: root/src/binary/reader.rs
diff options
context:
space:
mode:
authorEdward Barnard2017-03-06 21:08:58 +0000
committerEdward Barnard2017-03-06 21:08:58 +0000
commit1df5db005ea9959c4e19107997f446dc17095be4 (patch)
tree703c0f8b482ed563b72a2b76fc412f59ed3c6540 /src/binary/reader.rs
parente322e26b7e8c3dbfcba5c6142ca7559b63fc1652 (diff)
downloadrust-plist-1df5db005ea9959c4e19107997f446dc17095be4.tar.bz2
Limit the number of objects that can be created by the binary parser. Binary plists can contain circular references.
Diffstat (limited to 'src/binary/reader.rs')
-rw-r--r--src/binary/reader.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/binary/reader.rs b/src/binary/reader.rs
index e8a2bf8..770b12f 100644
--- a/src/binary/reader.rs
+++ b/src/binary/reader.rs
@@ -40,6 +40,11 @@ pub struct EventReader<R> {
// The largest single allocation allowed for this Plist.
// Equal to the number of bytes in the Plist minus the magic and trailer.
max_allocation: usize,
+ // The maximum number of objects that can be created. Default 10 * object_offsets.len().
+ // Binary plists can contain circular references.
+ max_objects: usize,
+ // The number of objects created so far.
+ current_objects: usize,
}
impl<R: Read + Seek> EventReader<R> {
@@ -50,7 +55,9 @@ impl<R: Read + Seek> EventReader<R> {
reader: reader,
ref_size: 0,
finished: false,
- max_allocation: 0
+ max_allocation: 0,
+ max_objects: 0,
+ current_objects: 0,
}
}
@@ -92,6 +99,8 @@ impl<R: Read + Seek> EventReader<R> {
try!(self.reader.seek(SeekFrom::Start(offset_table_offset)));
self.object_offsets = try!(self.read_ints(num_objects, offset_size));
+ self.max_objects = self.object_offsets.len() * 10;
+
// Seek to top object
self.stack.push(StackItem {
object_refs: vec![top_object],
@@ -164,6 +173,10 @@ impl<R: Read + Seek> EventReader<R> {
match object_ref {
Some(object_ref) => {
+ if self.current_objects > self.max_objects {
+ return Err(Error::InvalidData);
+ }
+ self.current_objects += 1;
try!(self.seek_to_object(object_ref));
}
None => {