-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
What did you do?
Trying to load and get data from a jp2 image
000137.zip
When working on my dataset, this issue occurred for ~50% of the images, but not for the remainder, so is intermittent.
This worked for me on a previously created python environment, but not a fresh one I created today (with nothing but conda install pillow). After some debugging on my end, I was able to determine that the error does NOT occur when downgrading to openjpeg version 2.4.0, but does occur with openjpeg version 2.5.2. The only difference in the PIL.report is the openjpeg version, and I'm able to repeatably break/fix the issue by upgrading/downgrading openjpeg.
I don't know if that makes in an openjpeg problem or a pillow problem, but I'm reporting here because this is the only imaging library I am familiar with, and thus the only place I know how to test and produce the error.
What did you expect to happen?
File loads and yields data
What actually happened?
Code crashes with the following error
File "<python-input-1>", line 1, in <module>
_ = Image.open('000137.jp2').getdata()
File "D:\Code\Miniconda\envs\piltest\Lib\site-packages\PIL\Image.py", line 1456, in getdata
self.load()
~~~~~~~~~^^
File "D:\Code\Miniconda\envs\piltest\Lib\site-packages\PIL\Jpeg2KImagePlugin.py", line 351, in load
return ImageFile.ImageFile.load(self)
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "D:\Code\Miniconda\envs\piltest\Lib\site-packages\PIL\ImageFile.py", line 319, in load
raise _get_oserror(err_code, encoder=False)
OSError: broken data stream when reading image fileWhat are your OS, Python and Pillow versions?
- OS: Windows 11
- Python: 3.13.2 (tested on various down to 3.8)
- Pillow: 11.1
--------------------------------------------------------------------
Pillow 11.1.0
Python 3.13.2 | packaged by Anaconda, Inc. | (main, Feb 6 2025, 18:49:14) [MSC v.1929 64 bit (AMD64)]
--------------------------------------------------------------------
Python executable is D:\Code\Miniconda\envs\piltest\python.exe
System Python files loaded from D:\Code\Miniconda\envs\piltest
--------------------------------------------------------------------
Python Pillow modules loaded from D:\Code\Miniconda\envs\piltest\Lib\site-packages\PIL
Binary Pillow modules loaded from D:\Code\Miniconda\envs\piltest\Lib\site-packages\PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 11.1.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.12.1
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.3.2
--- JPEG support ok, compiled for 9.0
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.2.13
--- LIBTIFF support ok, loaded 4.5.1
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
--------------------------------------------------------------------
Code for producing the error on that file:
from PIL import Image
_ = Image.open('000137.jp2').getdata()