diff --git a/Tests/images/zero_height.j2k b/Tests/images/zero_height.j2k new file mode 100644 index 00000000000..21bdd8f7667 Binary files /dev/null and b/Tests/images/zero_height.j2k differ diff --git a/Tests/test_imagefile.py b/Tests/test_imagefile.py index 0b3aecd0849..fc0fbfb9bbc 100644 --- a/Tests/test_imagefile.py +++ b/Tests/test_imagefile.py @@ -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, @@ -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") diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index 5e1dbbf683e..99b77a37f5f 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -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