mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-25 15:33:09 +03:00
Prevent reading past end of file pointer even if box length allows it
This commit is contained in:
parent
3ee5a9b094
commit
0c600f1d88
|
@ -33,12 +33,12 @@ class BoxReader:
|
||||||
self.remaining_in_box = -1
|
self.remaining_in_box = -1
|
||||||
|
|
||||||
def _can_read(self, num_bytes):
|
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:
|
if self.remaining_in_box >= 0:
|
||||||
# Inside box contents: ensure read does not go past box boundaries
|
# Inside box contents: ensure read does not go past box boundaries
|
||||||
return num_bytes <= self.remaining_in_box
|
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:
|
else:
|
||||||
return True # No length known, just read
|
return True # No length known, just read
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user