-
-
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
"TIFFAppendToStrip" when saving to BytesIO() stream #2206
Comments
I'll just note that the problem occurs when using any |
We've had something similar to this before: pr #1011, which fixed BytesIO saving of an image from libtiff. The tests for that image did test writing to a BytesIO, but not for group4. (https://github.com/python-pillow/Pillow/blob/master/Tests/test_file_libtiff.py#L457) I've added g4 compression to my local test, but did not trigger the issue with the existing test image. So it's not an fd issue. Saving to a BytesIO does work in at least one case. That being said, I can replicate your issue with your image. |
I had also observed that not all input images trigger this behavior. I apologize; that point should have been in the original description. Perhaps file size or size after compression are factors. In any case it does come down to some difference between TemporaryFile and BytesIO. |
Under the hood, there's a big difference. Anything with a real file pointer gets it passed to libtiff, anything without is written to memory, and then moved into the BytesIO. It looks like what's happening here is that the overflow check on realloc of the buffer is failing due to an invalid cast, or it was just an invalid check in the first place. If you can, try this branch: https://github.com/wiredfool/Pillow/tree/tiff_bytesio |
Tested ( |
What did you do?
Transcode a 1-bit PNG image to a CCITT Group 4 TIFF in memory.
The file is:
What did you expect to happen?
Expected writing to a BytesIO stream to work correctly, or for Pillow to reject saving to a BytesIO stream if a file descriptor is required.
What actually happened?
See error output below. It seems the problem is related to there not being a fileno associated with BytesIO.
What versions of Pillow and Python are you using?
macOS 10.11.6
Python 3.5.1 (homebrew)
Pillow==3.4.2
libtiff: stable 4.0.6 (bottled)
Code
Output
The text was updated successfully, but these errors were encountered: