Prevent reading past end of file pointer even if box length allows it

This commit is contained in:
Andrew Murray 2021-07-25 20:36:54 +10:00
parent 3ee5a9b094
commit 0c600f1d88

View File

@ -33,12 +33,12 @@ class BoxReader:
self.remaining_in_box = -1
def _can_read(self, num_bytes):
if self.has_length and self.fp.tell() + num_bytes > self.length:
# Outside box: ensure we don't read past the known file length
return False
if self.remaining_in_box >= 0:
# Inside box contents: ensure read does not go past box boundaries
return num_bytes <= self.remaining_in_box
elif self.has_length:
# Outside box: ensure we don't read past the known file length
return self.fp.tell() + num_bytes <= self.length
else:
return True # No length known, just read