mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Do not open images with zero or negative height
This commit is contained in:
parent
9d988dab6a
commit
886fcbe3d6
BIN
Tests/images/zero_height.j2k
Normal file
BIN
Tests/images/zero_height.j2k
Normal file
Binary file not shown.
|
@ -2,7 +2,15 @@ from io import BytesIO
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import BmpImagePlugin, EpsImagePlugin, Image, ImageFile, _binary, features
|
from PIL import (
|
||||||
|
BmpImagePlugin,
|
||||||
|
EpsImagePlugin,
|
||||||
|
Image,
|
||||||
|
ImageFile,
|
||||||
|
UnidentifiedImageError,
|
||||||
|
_binary,
|
||||||
|
features,
|
||||||
|
)
|
||||||
|
|
||||||
from .helper import (
|
from .helper import (
|
||||||
assert_image,
|
assert_image,
|
||||||
|
@ -377,3 +385,7 @@ class TestPyEncoder(CodecsTest):
|
||||||
|
|
||||||
with pytest.raises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
encoder.encode_to_file(None, None)
|
encoder.encode_to_file(None, None)
|
||||||
|
|
||||||
|
def test_zero_height(self):
|
||||||
|
with pytest.raises(UnidentifiedImageError):
|
||||||
|
Image.open("Tests/images/zero_height.j2k")
|
||||||
|
|
|
@ -123,7 +123,7 @@ class ImageFile(Image.Image):
|
||||||
) as v:
|
) as v:
|
||||||
raise SyntaxError(v) from 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")
|
raise SyntaxError("not identified by this driver")
|
||||||
except BaseException:
|
except BaseException:
|
||||||
# close the file only if we have opened it this constructor
|
# close the file only if we have opened it this constructor
|
||||||
|
|
Loading…
Reference in New Issue
Block a user