Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for reading DPI information from JPEG2000 images #5568

Merged
merged 8 commits into from
Aug 2, 2021
6 changes: 3 additions & 3 deletions src/PIL/Jpeg2KImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def __init__(self, fp, length=-1):
self.remaining_in_box = -1

def _can_read(self, num_bytes):
if self.has_length and self.fp.tell() + num_bytes > self.length:
# Outside box: ensure we don't read past the known file length
return False
if self.remaining_in_box >= 0:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could technically also be an elif for symmetry and whatnot -- not that it matters, since we return from the previous if branch anyway. 👍 on spotting and fixing the bug where we could read past the parent box length!

# Inside box contents: ensure read does not go past box boundaries
return num_bytes <= self.remaining_in_box
elif self.has_length:
# Outside box: ensure we don't read past the known file length
return self.fp.tell() + num_bytes <= self.length
else:
return True # No length known, just read

Expand Down