Repository navigation
BUG: implement SeekableFileObject.readline for Pillow HTTP streams (#1007) - #1209
Merged
Merged
Conversation
Contributor
|
Okay, this is indeed a bug and your PR fixes it so this shall be merged. A bit curious how you encountered it. From what I can see the way you would be able to trigger this is if you read some super old pillow formats directly from web. That's XM, XV Thumbnails and IFUNC Image Memory ... those formats predate the 2000s and I thought they would be long resting in peace by now. The world is a wondrous place :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1007.
SeekableFileObject is the wrapper ImageIO puts around HTTP (and zip)
streams so Pillow can seek. Pillow's IM plugin is always probed once
Image.open falls through the common formats (
acceptis None), andXPM/IM parse headers with
fp.readline(). A missingreadlineraisedAttributeError, which neither Pillow nor imopen's try-all path treat
as "wrong plugin."
#1084 added a stub (
yield from self._file.readline()). That neverreturned line bytes: the wrapped handle is
self.f, andyield frommakes a generator. JPEG/WebP still opened because Pillow swallows
TypeError from that generator; formats that actually need readline
(XPM) still failed. Delegating to
self.f.readline()would also bewrong after
Request.firstbyteshas already read 256 bytes and seekedthe wrapper back to 0.
What I chose: BytesIO-compatible
readline(size=-1)through theexisting buffer (stop at newline, EOF, or
size).Alternative:
return self.read(100)(reporter), always consume theremainder with no newline scan (suggested on #1007), or catch
AttributeError in imopen's try-all.
Reason:
seek()already mimics BytesIO; BytesIO.readline isalready "until newline or EOF," which is "no EOL → rest of the file"
plus the correct stop when a newline exists. Catching AttributeError
would hide the next missing file method.
Happy to switch to always-read-rest if that is preferred.
Note to Maintainers
Remember to squash-merge the PR and to use an appropriate tag in the commit
message title.