Skip to content

Commit

Permalink
Only read until the offset of the next tile
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 19, 2024
1 parent cbc55c4 commit 109de5d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/PIL/ImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def load(self) -> Image.core.PixelAccess | None:
self.tile, lambda tile: (tile[0], tile[1], tile[3])
)
]
for decoder_name, extents, offset, args in self.tile:
for i, (decoder_name, extents, offset, args) in enumerate(self.tile):
seek(offset)
decoder = Image._getdecoder(
self.mode, decoder_name, args, self.decoderconfig
Expand All @@ -276,8 +276,13 @@ def load(self) -> Image.core.PixelAccess | None:
else:
b = prefix
while True:
read_bytes = self.decodermaxblock
if i + 1 < len(self.tile):
next_offset = self.tile[i + 1].offset
if next_offset > offset:
read_bytes = next_offset - offset
try:
s = read(self.decodermaxblock)
s = read(read_bytes)
except (IndexError, struct.error) as e:
# truncated png/gif
if LOAD_TRUNCATED_IMAGES:
Expand Down

0 comments on commit 109de5d

Please sign in to comment.