Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Tests/test_imagefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ def test_ico(self) -> None:
assert p.image is not None
assert (48, 48) == p.image.size

@pytest.mark.filterwarnings("ignore:Corrupt EXIF data")
def test_incremental_tiff(self) -> None:
with ImageFile.Parser() as p:
with open("Tests/images/hopper.tif", "rb") as f:
p.feed(f.read(1024))

# Check that insufficient data was given in the first feed
assert not p.image

p.feed(f.read())
assert p.image is not None
assert (128, 128) == p.image.size

@skip_unless_feature("webp")
def test_incremental_webp(self) -> None:
with ImageFile.Parser() as p:
Expand Down
8 changes: 6 additions & 2 deletions src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,8 +1433,12 @@ def _setup(self) -> None:
logger.debug("- YCbCr subsampling: %s", self.tag_v2.get(YCBCRSUBSAMPLING))

# size
xsize = self.tag_v2.get(IMAGEWIDTH)
ysize = self.tag_v2.get(IMAGELENGTH)
try:
xsize = self.tag_v2[IMAGEWIDTH]
ysize = self.tag_v2[IMAGELENGTH]
except KeyError as e:
msg = "Missing dimensions"
raise TypeError(msg) from e
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a new error type that was not raised in past versions, isn't it? So i will also make trouble in Django...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's a good idea to always raise a special error for all parsers, in all cases where the chunk data will not be enough to get the meta data and use RuntimeError as a base, because it's already catch?

Copy link
Member Author

@radarhere radarhere Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 10.4.0, a TypeError would have been raised here by int(self.tag_v2.get(IMAGEWIDTH)) being run when there was no IMAGEWIDTH tag - effectively, int(None).

This is raising a TypeError again.

It is then caught in Image.open, and if no other formats think they can interpret the file, an UnidentifiedImageError is raised, which inherits from OSError, and is then caught in Parser.feed(), and the Django loop continues, unaware of the error.

if not isinstance(xsize, int) or not isinstance(ysize, int):
msg = "Invalid dimensions"
raise ValueError(msg)
Expand Down
Loading