JPEG 2000 support broken in latest version?

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
johan
Posts: 7
Joined: 2010-10-12T09:08:23-07:00
Authentication code: 8675308

JPEG 2000 support broken in latest version?

Post by johan »

After upgrading to the latest version of ImageMagick JPEG 2000 support seems to be somehow broken. For instance, trying to do this:

Code: Select all

identify target.jp2
gives me a segmentation fault. Ditto for any other operations (convert, compare, etc.) on JPEG 2000 images. Other JP2 images give me errors such as:

Code: Select all

error: cannot decode code stream
identify.exe: unable to decode image file `balloon_kdu.jp2' @ error/jp2.c/ReadJP2Image/402.
I remember encountering similar issues in previous versions of IM, but only for large images (most likely related the underlying JasPer library, which appears to have pretty poor memory management). But now I'm also getting this for very small (e.g. 138 kB lossless!) images!

Some aditional info on my IM version and my system:

IM:

Code: Select all

Version: ImageMagick 6.7.9-1 2012-08-21 Q8 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
Config:

Code: Select all

$ identify -list configure

Path: [built-in]

Name          Value
-------------------------------------------------------------------------------
NAME          ImageMagick

Path: C:\Program Files\ImageMagick-6.7.9-Q8\configure.xml

Name          Value
-------------------------------------------------------------------------------
CC            vs10
COPYRIGHT     Copyright (C) 1999-2012 ImageMagick Studio LLC
DELEGATES     bzlib freetype jpeg jp2 lcms png tiff x11 xml wmf zlib
FEATURES      OpenMP
HOST          Windows
LIB_VERSION   0x679
LIB_VERSION_NUMBER 6,7,9,0
NAME          ImageMagick
RELEASE_DATE  2012-09-01
VERSION       6.7.9
WEBSITE       http://www.imagemagick.org
System:

Code: Select all

OS Name:                   Microsoft Windows XP Professional
OS Version:                5.1.2600 Service Pack 3 Build 2600
OS Configuration:          Member Workstation
OS Build Type:             Multiprocessor Free
System type:               X86-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: x86 Family 15 Model 6 Stepping 5 GenuineIntel ~2992 Mhz
BIOS Version:              HPQOEM - 20070413
Total Physical Memory:     999 MB
Available Physical Memory: 138 MB
Virtual Memory: Max Size:  2,048 MB
UPDATE:
Since I submitted this bug I did some additional tests, and I think there are at least 2 issues here. For convenience I uploaded a ZIP file with 3 test images here:

http://dl.dropbox.com/u/9523497/testIM.zip

Here's what happens if I try to identify each of them:

1. Small test image with embedded ICC profile

Code: Select all

$ identify target.jp2
Segmentation fault
2. Same image as above, but without the embedded ICC profile

Code: Select all

$ identify target_noICC.jp2
target_noICC.jp2 JP2 437x303 437x303+0+0 8-bit RGB 137KB 0.141u 0:00.141
So this works fine.

3. Finally this one (no embedded ICC profiles, slightly larger, but still pretty small):

Code: Select all

$ identify balloon.jp2
error: cannot decode code stream
identify.exe: unable to decode image file `balloon.jp2' @ error/jp2.c/ReadJP2Image/402.
This looks like another problem altogether, but I have no idea why it is happening!
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

Re: JPEG 2000 support broken in latest version?

Post by pipitas »

I tested it on a Mac OSX Lion with this:

Code: Select all

identify -version
  Version: ImageMagick 6.7.9-0 2012-08-17 Q16 http://www.imagemagick.org
  Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
  Features:  OpenCL HDRI


Also a problem with target.jp2 (but with a somewhat different message):

Code: Select all

identify target.jp2 
  Assertion failed: (iccprof), function jp2_decode, file jp2_dec.c, line 294.
  Abort trap: 6
No problem with balloon.jp2:

Code: Select all

identify balloon.jp2 
  balloon.jp2 JP2 2717x3701 2717x3701+0+0 8-bit DirectClass 670KB 1.520u 0:01.809
No problem with target_noICC.jp2:

Code: Select all

identify target_noICC.jp2 
  target_noICC.jp2 JP2 437x303 437x303+0+0 8-bit DirectClass 137KB 0.060u 0:00.05
rspencer
Posts: 1
Joined: 2012-08-27T07:06:59-07:00
Authentication code: 67789

Re: JPEG 2000 support broken in latest version?

Post by rspencer »

Ubuntu:

Code: Select all

Distributor ID:	Ubuntu
Description:	Ubuntu 12.04 LTS
Release:	12.04
Codename:	precise
Identify version:

Code: Select all

Version: ImageMagick 6.6.9-7 2012-04-30 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP   
Other images work fine, the target.jp2 creates the same problem as pipitas:

Code: Select all

identify target.jp2
identify: jp2_dec.c:294: jp2_decode: Assertion `iccprof' failed.
Aborted (core dumped)
As expected this is the same in the Jasper output:

Jasper / ImgInfo version:

Code: Select all

imginfo --version
1.900.1
And the image output:

Code: Select all

imginfo: jp2_dec.c:294: jp2_decode: Assertion `iccprof' failed.
Aborted (core dumped)
@johan - might be worth just checking the output in imginfo for each of these things, I suspect the balloon.jp2 issue is on old versions of Jasper, but the target.jp2 issue will still remain. If this is possible on your windows installation anyhow.
johan
Posts: 7
Joined: 2010-10-12T09:08:23-07:00
Authentication code: 8675308

Re: JPEG 2000 support broken in latest version?

Post by johan »

OK, forgot about my suggestion below, I managed to hack into the ICC profile (oldskool hex-editing skills!) and manually changed the zero value, and it still gives me the same problem. So it must be something else!

I can also add that I was able to reproduce this problem with the Windows binaries of GeoJasper (no Win binaries for the 'regular' JasPer version exist as far as I know), so this is definitely a JasPer issue.
UPDATE: I just ran both the Adobe RGB and the eciRGB JP2s through ExifTool (used exiftool with -X switch). Results below:

1. JP2 that produces error:

Code: Select all

  <ICC_Profile:ProfileDescription>eciRGB v2</ICC_Profile:ProfileDescription> 
  <ICC_Profile:MediaWhitePoint>0.9642 1 0.82491</ICC_Profile:MediaWhitePoint> 
  <ICC_Profile:RedTRC>(Binary data 1412 bytes, use -b option to extract)</ICC_Profile:RedTRC> 
  <ICC_Profile:GreenTRC>(Binary data 1412 bytes, use -b option to extract)</ICC_Profile:GreenTRC> 
  <ICC_Profile:BlueTRC>(Binary data 1412 bytes, use -b option to extract)</ICC_Profile:BlueTRC> 
  <ICC_Profile:RedMatrixColumn>0.65027 0.32028 0</ICC_Profile:RedMatrixColumn> 
  <ICC_Profile:GreenMatrixColumn>0.17804 0.60205 0.06783</ICC_Profile:GreenMatrixColumn> 
  <ICC_Profile:BlueMatrixColumn>0.13588 0.07767 0.75708</ICC_Profile:BlueMatrixColumn>
2. JP2 that doesn't produce error:

Code: Select all

 <ICC_Profile:ProfileDescription>Adobe RGB (1998)</ICC_Profile:ProfileDescription> 
  <ICC_Profile:MediaWhitePoint>0.95045 1 1.08905</ICC_Profile:MediaWhitePoint> 
  <ICC_Profile:MediaBlackPoint>0 0 0</ICC_Profile:MediaBlackPoint> 
  <ICC_Profile:RedTRC>(Binary data 14 bytes, use -b option to extract)</ICC_Profile:RedTRC> 
  <ICC_Profile:GreenTRC>(Binary data 14 bytes, use -b option to extract)</ICC_Profile:GreenTRC> 
  <ICC_Profile:BlueTRC>(Binary data 14 bytes, use -b option to extract)</ICC_Profile:BlueTRC> 
  <ICC_Profile:RedMatrixColumn>0.60974 0.31111 0.01947</ICC_Profile:RedMatrixColumn> 
  <ICC_Profile:GreenMatrixColumn>0.20528 0.62567 0.06087</ICC_Profile:GreenMatrixColumn> 
  <ICC_Profile:BlueMatrixColumn>0.14919 0.06322 0.74457</ICC_Profile:BlueMatrixColumn> 
What immediately caught my eye was the last coefficient in the red matrix column of the problematic image, which is 0 (zero). Now I'm not very familiar with the finer details of the colour transformations involved, and calling my knowledge of matrix algebra rusty would be an understatement. Having said that: could this perhaps, somehow, result in a zero-division somewhere in JasPer? Just a (very) wild guess ...
Post Reply