Merge pull request #5919 from radarhere/duplicate

Remove consecutive duplicates that only differ by their offset
This commit is contained in:
Andrew Murray 2022-01-01 15:35:10 +11:00 committed by GitHub
commit a8f90a3916
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

Binary file not shown.

View File

@ -3,7 +3,7 @@ from io import BytesIO
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 (
@ -726,6 +726,14 @@ class TestFileTiff:
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:

View File

@ -28,6 +28,7 @@
#
import io
import itertools
import struct
import sys
@ -210,6 +211,13 @@ class ImageFile(Image.Image):
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