Skip to content

Catch KeyError when checking mode from PNG IHDR chunk#9604

Open
radarhere wants to merge 2 commits intopython-pillow:mainfrom
radarhere:png_mode
Open

Catch KeyError when checking mode from PNG IHDR chunk#9604
radarhere wants to merge 2 commits intopython-pillow:mainfrom
radarhere:png_mode

Conversation

@radarhere
Copy link
Copy Markdown
Member

try:
self.im_mode, self.im_rawmode = _MODES[(s[8], s[9])]
except Exception:
pass

Exception can be made more specific. It is a KeyError that will be raised if the bit depth / color type combination doesn't have a match.

If you're concerned that s might not be long enough for s[9], the length has been checked a few lines earlier.

s = ImageFile._safe_read(self.fp, length)
if length < 13:
if ImageFile.LOAD_TRUNCATED_IMAGES:
return s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant