Skip to content

Commit

Permalink
Merge pull request #5919 from radarhere/duplicate
Browse files Browse the repository at this point in the history
Remove consecutive duplicates that only differ by their offset
  • Loading branch information
radarhere committed Jan 1, 2022
2 parents 89d0d38 + 7370a0b commit a8f90a3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Binary file added Tests/images/timeout-6646305047838720
Binary file not shown.
10 changes: 9 additions & 1 deletion Tests/test_file_tiff.py
Expand Up @@ -3,7 +3,7 @@

import pytest

from PIL import Image, TiffImagePlugin
from PIL import Image, ImageFile, TiffImagePlugin
from PIL.TiffImagePlugin import RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION

from .helper import (
Expand Down Expand Up @@ -726,6 +726,14 @@ def test_string_dimension(self):
with pytest.raises(OSError):
im.load()

@pytest.mark.timeout(6)
@pytest.mark.filterwarnings("ignore:Truncated File Read")
def test_timeout(self):
with Image.open("Tests/images/timeout-6646305047838720") as im:
ImageFile.LOAD_TRUNCATED_IMAGES = True
im.load()
ImageFile.LOAD_TRUNCATED_IMAGES = False


@pytest.mark.skipif(not is_win32(), reason="Windows only")
class TestFileTiffW32:
Expand Down
8 changes: 8 additions & 0 deletions src/PIL/ImageFile.py
Expand Up @@ -28,6 +28,7 @@
#

import io
import itertools
import struct
import sys

Expand Down Expand Up @@ -210,6 +211,13 @@ def load(self):
except AttributeError:
prefix = b""

# Remove consecutive duplicates that only differ by their offset
self.tile = [
list(tiles)[-1]
for _, tiles in itertools.groupby(
self.tile, lambda tile: (tile[0], tile[1], tile[3])
)
]
for decoder_name, extents, offset, args in self.tile:
decoder = Image._getdecoder(
self.mode, decoder_name, args, self.decoderconfig
Expand Down

0 comments on commit a8f90a3

Please sign in to comment.