-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Prevent extra EPS header validations #8144
Conversation
It's already been called by this point.
Pillow/src/PIL/EpsImagePlugin.py Line 228 in 6a6ad65
The image data part of the code can't be reached until Pillow/src/PIL/EpsImagePlugin.py Line 300 in 6a6ad65
Pillow/src/PIL/EpsImagePlugin.py Line 327 in 6a6ad65
But it is only set to false after Pillow/src/PIL/EpsImagePlugin.py Lines 291 to 292 in 6a6ad65
Pillow/src/PIL/EpsImagePlugin.py Lines 307 to 308 in 6a6ad65
If anyone is looking at this and thinks 'What about the size check?' Pillow/src/PIL/EpsImagePlugin.py Lines 370 to 372 in 6a6ad65
That has to be set by the end of the image data part of the code. Pillow/src/PIL/EpsImagePlugin.py Line 356 in 6a6ad65
So the change suggested here doesn't make any functional difference. |
So actually, if |
Ok, you're describing diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py
index 380b1cf0e..20ef0e5e2 100644
--- a/src/PIL/EpsImagePlugin.py
+++ b/src/PIL/EpsImagePlugin.py
@@ -270,6 +270,7 @@ class EpsImageFile(ImageFile.ImageFile):
if byte == b"":
# if we didn't read a byte we must be at the end of the file
if bytes_read == 0:
+ check_required_header_comments()
break
elif byte in b"\r\n":
# if we read a line ending character, ignore it and parse what
@@ -365,8 +366,6 @@ class EpsImageFile(ImageFile.ImageFile):
trailer_reached = True
bytes_read = 0
- check_required_header_comments()
-
if not self._size:
msg = "cannot determine EPS bounding box"
raise OSError(msg) Sure, that looks correct, if you like it as a fractional performance increase. |
I think your first commit could be removed? As I was saying, it doesn't make any functional difference. It just unnecessarily runs the check(s) at the end. |
I think it makes the function easier to read by only having |
I don't personally agree, but we can see what others think. |
I'm generally a fan of early exit rather than introducing conditional checks to allow a method to run to completion when there shouldn't be code executed anyway. |
I would normally agree, but in this case this is the only return in the method, and it's inside a loop, so it's easy to miss it, and this change also stops the check from happening twice in some situations. |
As per my earlier comment, the |
bf014af
to
a2c0a90
Compare
I still think it's bad form to have that return there, but I've removed the first commit and rebased on main. |
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
a8b6858
to
065aeae
Compare
This is the only return statement in this function, and it appears to be unnecessary since breaking from the loop at this location accomplishes the same thing, and matches what the rest of this loop does.
The only change is that
check_required_header_comments()
is called at the end of the function. This was being skipped before due to the early return, but it will be called now that it's just breaking from the loop.Before 8f75cc2 this return was inside a nested loop, so breaking wouldn't have worked, but now it does. Also,
check_required_header_comments()
didn't exist at that time, so the early return wasn't skipping anything.