Raise UnidentifiedImageError when opening TIFF without dimensions#8535
Raise UnidentifiedImageError when opening TIFF without dimensions#8535hugovk merged 1 commit intopython-pillow:mainfrom
Conversation
| ysize = self.tag_v2[IMAGELENGTH] | ||
| except KeyError as e: | ||
| msg = "Missing dimensions" | ||
| raise TypeError(msg) from e |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Resolves #8530
#8319 changed
to
Pillow/src/PIL/TiffImagePlugin.py
Lines 1436 to 1440 in 82199ef
This change seems reasonable, especially when you consider #4103.
However, if IMAGEWIDTH or IMAGELENGTH were missing, then
int(None)previously raised a TypeError. TypeErrors are caught when opening imagesPillow/src/PIL/Image.py
Lines 3497 to 3506 in 82199ef
but the ValueErrors are not.
So this change inadvertently broke feeding a TIFF image to
ImageFile.Parser, which relies on OSError (which UnidentifiedImageErrors are) to know that there isn't enough data yet.Pillow/src/PIL/ImageFile.py
Lines 468 to 473 in 82199ef
This PR changes the code to raise a TypeError again.