Skip to content

Commit

Permalink
Do not allow negative height
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed May 4, 2022
1 parent 9d988da commit 12c8e6d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
Binary file added Tests/images/negative_height.j2k
Binary file not shown.
5 changes: 5 additions & 0 deletions Tests/test_file_jpeg2k.py
Expand Up @@ -150,6 +150,11 @@ def test_reduce():
assert im.size == (40, 30)


def test_negative_height():
with Image.open("Tests/images/negative_height.j2k") as im:
assert im.size[1] == 0


def test_load_dpi():
with Image.open("Tests/images/test-card-lossless.jp2") as im:
assert im.info["dpi"] == (71.9836, 71.9836)
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/Jpeg2KImagePlugin.py
Expand Up @@ -109,7 +109,7 @@ def _parse_codestream(fp):
for i in range(csiz):
ssiz[i], xrsiz[i], yrsiz[i] = struct.unpack_from(">BBB", siz, 36 + 3 * i)

size = (xsiz - xosiz, ysiz - yosiz)
size = (xsiz - xosiz, max(0, ysiz - yosiz))
if csiz == 1:
if (yrsiz[0] & 0x7F) > 8:
mode = "I;16"
Expand Down

0 comments on commit 12c8e6d

Please sign in to comment.