Skip to content

Commit a8f90a3

Browse files
authored
Merge pull request #5919 from radarhere/duplicate
Remove consecutive duplicates that only differ by their offset
2 parents 89d0d38 + 7370a0b commit a8f90a3

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Tests/images/timeout-6646305047838720

67.9 KB
Binary file not shown.

Tests/test_file_tiff.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from PIL import Image, TiffImagePlugin
6+
from PIL import Image, ImageFile, TiffImagePlugin
77
from PIL.TiffImagePlugin import RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION
88

99
from .helper import (
@@ -726,6 +726,14 @@ def test_string_dimension(self):
726726
with pytest.raises(OSError):
727727
im.load()
728728

729+
@pytest.mark.timeout(6)
730+
@pytest.mark.filterwarnings("ignore:Truncated File Read")
731+
def test_timeout(self):
732+
with Image.open("Tests/images/timeout-6646305047838720") as im:
733+
ImageFile.LOAD_TRUNCATED_IMAGES = True
734+
im.load()
735+
ImageFile.LOAD_TRUNCATED_IMAGES = False
736+
729737

730738
@pytest.mark.skipif(not is_win32(), reason="Windows only")
731739
class TestFileTiffW32:

src/PIL/ImageFile.py

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#
2929

3030
import io
31+
import itertools
3132
import struct
3233
import sys
3334

@@ -210,6 +211,13 @@ def load(self):
210211
except AttributeError:
211212
prefix = b""
212213

214+
# Remove consecutive duplicates that only differ by their offset
215+
self.tile = [
216+
list(tiles)[-1]
217+
for _, tiles in itertools.groupby(
218+
self.tile, lambda tile: (tile[0], tile[1], tile[3])
219+
)
220+
]
213221
for decoder_name, extents, offset, args in self.tile:
214222
decoder = Image._getdecoder(
215223
self.mode, decoder_name, args, self.decoderconfig

0 commit comments

Comments
 (0)