Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Image.open() fails for JPEG 2000 with embedded ICC profile

Open hajimen opened this issue 7 years ago • 4 comments

What did you do?

I tried to open a JPEG 2000 file here. (https://github.com/openpreserve/format-corpus/blob/master/jp2k-test/icc/balloon_eciRGBv2_aware.jp2)

The image can be opened by IrfanView, GIMP and read by ImageMagick.

What actually happened?

OSError: cannot identify image file 'balloon_eciRGBv2_aware.jp2'

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: Python 3.6.6 :: Anaconda custom (64-bit)
  • Pillow: 5.4.0 conda-forge
bim = Image.open('balloon_eciRGBv2_aware.jp2')
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-7-9e62275bed11> in <module>()
----> 1 bim = Image.open('balloon_eciRGBv2_aware.jp2')

~\Anaconda3-5\lib\site-packages\PIL\Image.py in open(fp, mode)
   2685         warnings.warn(message)
   2686     raise IOError("cannot identify image file %r"
-> 2687                   % (filename if filename else fp))
   2688 
   2689 #

OSError: cannot identify image file 'balloon_eciRGBv2_aware.jp2'

hajimen avatar Jan 07 '19 09:01 hajimen

The error is being caused by struct.error: unpack requires a bytes object of length 8 at https://github.com/python-pillow/Pillow/blob/7bf5246b93cc89cfb9d6cca78c4719a943b10585/src/PIL/Jpeg2KImagePlugin.py#L96

The code would normally have broken out of the loop before that. This section of the code is trying to find the image mode. However, it does not handle the case where meth is 2, which signifies the Restricted ICC profile.

radarhere avatar Jan 07 '19 10:01 radarhere

whats the progress on this?

zoj613 avatar May 07 '20 20:05 zoj613

Any news?

KirschbaumP avatar Nov 11 '20 11:11 KirschbaumP

I've created PR #5654 to resolve this.

radarhere avatar Aug 04 '21 15:08 radarhere