mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-03 21:24:31 +03:00
Merge pull request #8146 from Yay295/jp2_parsing
This commit is contained in:
commit
2756cd5273
BIN
Tests/images/unknown_mode.j2k
Normal file
BIN
Tests/images/unknown_mode.j2k
Normal file
Binary file not shown.
|
@ -335,6 +335,12 @@ def test_issue_6194() -> None:
|
|||
assert im.getpixel((5, 5)) == 31
|
||||
|
||||
|
||||
def test_unknown_j2k_mode() -> None:
|
||||
with pytest.raises(UnidentifiedImageError):
|
||||
with Image.open("Tests/images/unknown_mode.j2k"):
|
||||
pass
|
||||
|
||||
|
||||
def test_unbound_local() -> None:
|
||||
# prepatch, a malformed jp2 file could cause an UnboundLocalError exception.
|
||||
with pytest.raises(UnidentifiedImageError):
|
||||
|
|
|
@ -97,7 +97,7 @@ class BoxReader:
|
|||
return tbox
|
||||
|
||||
|
||||
def _parse_codestream(fp):
|
||||
def _parse_codestream(fp) -> tuple[tuple[int, int], str]:
|
||||
"""Parse the JPEG 2000 codestream to extract the size and component
|
||||
count from the SIZ marker segment, returning a PIL (size, mode) tuple."""
|
||||
|
||||
|
@ -122,7 +122,8 @@ def _parse_codestream(fp):
|
|||
elif csiz == 4:
|
||||
mode = "RGBA"
|
||||
else:
|
||||
mode = ""
|
||||
msg = "unable to determine J2K image mode"
|
||||
raise SyntaxError(msg)
|
||||
|
||||
return size, mode
|
||||
|
||||
|
@ -237,10 +238,6 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
|
|||
msg = "not a JPEG 2000 file"
|
||||
raise SyntaxError(msg)
|
||||
|
||||
if self.size is None or not self.mode:
|
||||
msg = "unable to determine size/mode"
|
||||
raise SyntaxError(msg)
|
||||
|
||||
self._reduce = 0
|
||||
self.layers = 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user