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

Do not open images with zero or negative height #6269

Merged
merged 1 commit into from May 4, 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/zero_height.j2k
Binary file not shown.
14 changes: 13 additions & 1 deletion Tests/test_imagefile.py
Expand Up @@ -2,7 +2,15 @@

import pytest

from PIL import BmpImagePlugin, EpsImagePlugin, Image, ImageFile, _binary, features
from PIL import (
BmpImagePlugin,
EpsImagePlugin,
Image,
ImageFile,
UnidentifiedImageError,
_binary,
features,
)

from .helper import (
assert_image,
Expand Down Expand Up @@ -377,3 +385,7 @@ def test_encode(self):

with pytest.raises(NotImplementedError):
encoder.encode_to_file(None, None)

def test_zero_height(self):
with pytest.raises(UnidentifiedImageError):
Image.open("Tests/images/zero_height.j2k")
2 changes: 1 addition & 1 deletion src/PIL/ImageFile.py
Expand Up @@ -123,7 +123,7 @@ def __init__(self, fp=None, filename=None):
) as v:
raise SyntaxError(v) from v

if not self.mode or self.size[0] <= 0:
if not self.mode or self.size[0] <= 0 or self.size[1] <= 0:
raise SyntaxError("not identified by this driver")
except BaseException:
# close the file only if we have opened it this constructor
Expand Down