Skip to content

Commit 184b73e

Browse files
radarherehugovk
authored andcommitted
Do not open images with zero or negative height
1 parent 5d07022 commit 184b73e

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

Tests/images/zero_height.j2k

3.79 KB
Binary file not shown.

Tests/test_imagefile.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
import pytest
44

5-
from PIL import BmpImagePlugin, EpsImagePlugin, Image, ImageFile, _binary, features
5+
from PIL import (
6+
BmpImagePlugin,
7+
EpsImagePlugin,
8+
Image,
9+
ImageFile,
10+
UnidentifiedImageError,
11+
_binary,
12+
features,
13+
)
614

715
from .helper import (
816
assert_image,
@@ -377,3 +385,7 @@ def test_encode(self):
377385

378386
with pytest.raises(NotImplementedError):
379387
encoder.encode_to_file(None, None)
388+
389+
def test_zero_height(self):
390+
with pytest.raises(UnidentifiedImageError):
391+
Image.open("Tests/images/zero_height.j2k")

src/PIL/ImageFile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def __init__(self, fp=None, filename=None):
123123
) as v:
124124
raise SyntaxError(v) from v
125125

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

0 commit comments

Comments
 (0)