Do not open images with zero or negative height

This commit is contained in:
Andrew Murray 2022-05-04 21:25:40 +10:00
parent 9d988dab6a
commit 886fcbe3d6
3 changed files with 14 additions and 2 deletions

Binary file not shown.

View File

@ -2,7 +2,15 @@ from io import BytesIO
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 @@ class TestPyEncoder(CodecsTest):
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")

View File

@ -123,7 +123,7 @@ class ImageFile(Image.Image):
) 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