-
-
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
np.array(img) should not hide errors for corrupted images #5084
Comments
When I try and replicate this, I find that img.__array_interface__ throws an OSError, but np.array(img) doesn't. So depending on how you look at this, the problem is either that Pillow's |
I think this shows up in other guises, like #3863 Masking the real error is not ideal indeed. |
Confirmed to be a bug in numpy - see the discussion starting at https://gitter.im/numpy/numpy?at=6067b4ef3153ce63a3b6dcad We could raise a |
I've taken the suggestion of using |
NumPy 1.23 has been released, fixing the bug. The Pillow workaround has been reverted, and will no longer be present in the next release of Pillow. |
What did you do?
I spent a lot of time debugging a code which loads png images from disk and converts them to numpy arrays to do some processing.
What did you expect to happen?
If I take any png and corrupt it, say, by truncating,
I expect the following code to fail with some exception because image pixels can not be read into an array.
What actually happened?
Instead, I got an object array with a single element:
>>> print(arr) <PIL.PngImagePlugin.PngImageFile image mode=RGB size=384x288 at 0x7F38258C6240>
and now the code fails later with a strange error message, like:
img.verify() behaves strangely, too
Funny and counter-intuitive thing, if I try instead doing:
I still got an error presumably because calling verify() makes image unusable, but again, np.array() doesn't care. So now the code fails for all good images.
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: