Skip to content

Commit

Permalink
raise SyntaxError when parsing codestream rather than returning None
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 authored Jun 17, 2024
1 parent 99dd553 commit d3ee66e
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/PIL/Jpeg2KImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def next_box_type(self) -> bytes:
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."""

Expand All @@ -122,7 +122,8 @@ def _parse_codestream(fp):
elif csiz == 4:
mode = "RGBA"
else:
mode = None
msg = "unable to determine JP2 image mode"
raise SyntaxError(msg)

return size, mode

Expand Down Expand Up @@ -237,10 +238,6 @@ def _open(self) -> None:
msg = "not a JPEG 2000 file"
raise SyntaxError(msg)

if self.size is None or self.mode is None:
msg = "unable to determine size/mode"
raise SyntaxError(msg)

self._reduce = 0
self.layers = 0

Expand Down

0 comments on commit d3ee66e

Please sign in to comment.