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
Inconsistent behavior opening truncated JPEG file #2977
Comments
Many viewers can see it but |
We do throw an error on the first try, but apparently it's silently caught and discarded in numpy. Though, it is a bit of a puzzle as to why it succeeds the second time after the initial failure due to a truncated file. >>> im = Image.open('36444958735_32c0410b64_o.jpg')
>>> im.__array_interface__.keys()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/erics/vpy35/lib/python3.5/site-packages/Pillow-5.0.0-py3.5-linux-x86_64.egg/PIL/Image.py", line 673, in __array_interface__
File "/home/erics/vpy35/lib/python3.5/site-packages/Pillow-5.0.0-py3.5-linux-x86_64.egg/PIL/Image.py", line 720, in tobytes
File "/home/erics/vpy35/lib/python3.5/site-packages/Pillow-5.0.0-py3.5-linux-x86_64.egg/PIL/ImageFile.py", line 233, in load
OSError: image file is truncated (13 bytes not processed)
>>> im.__array_interface__.keys()
dict_keys(['version', 'shape', 'data', 'typestr'])
>>> This is consistent behavior with two load calls, so it's something in the ImageFile code handling truncated files where it's not cleaning up the failure properly, and allowing the attempt to do it again. |
With #3965, the behaviour is now consistent - the shape is empty for both calls. |
You may also be interested to know that if you use from PIL import Image, ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
import numpy as np
a=Image.open('aa.jpg')
b1=np.array(a)
print(b1.shape) # (2000, 2000, 3)
b2=np.array(a)
print(b2.shape) # (2000, 2000, 3) |
The fact that the errors are silenced is actually acknowledged as a problem with numpy - numpy/numpy#11629. So I'm going to close this. |
What did you do?
What did you expect to happen?
b1.shape == b2.shape == (H,W,3)
What actually happened?
Surprisingly,
b1.shape == ()
andb2.shape == (H, W, 3)
.b1:
array(<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=2000x2000 at 0x7FCD...48>, dtype=object)
I have a large RAM available (>50G).
This is consistently reproduced for a specific image file:
https://farm5.staticflickr.com/4360/36444958735_32c0410b64_o.jpg
What versions of Pillow and Python are you using?
5.1.0.dev0 && 4.3.0 (pip version)
Python 3.6.4
The text was updated successfully, but these errors were encountered: