Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove consecutive duplicate tiles that only differ by their offset #5919

Merged
merged 1 commit into from Jan 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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