Skip to main content

JAI + JPEG2000: EOF reached before finding Contiguous Codestream Box

10 replies [Last post]
miclom
Offline
Joined: 2009-07-02
Points: 0

Hi, i use:
jai_imageio 1.0_01, jai_codec 1.1.2_01, jai_core 1.1.2_01.

When i try read image .JPEG2000 from file i get error:

java.lang.RuntimeException: EOF reached before finding Contiguous Codestream Box
at
com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.initializeRead(J2KReadState.java:592)
at
com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.(J2KReadState.java:153)
at
com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader.read(J2KImageReader.java:347)
at javax.imageio.ImageReader.read(ImageReader.java:923)
... myclasses
Caused by: java.lang.Error: EOF reached before finding Contiguous Codestream Box
at
jj2000.j2k.fileformat.reader.FileFormatReader.readFileFormat(FileFormatReader.java:286)
at
com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.initializeRead(J2KReadState.java:373)
... 5 more

I test this same application with other images and don't have any problem. Maybe you know solution of this problem ...

thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
budait
Offline
Joined: 2009-07-08
Points: 0

Have same exception using jai-imageio 1.1

http://www.savefile.com/files/2148069

How to solve this issue?

Message was edited by: budait

marksmys
Offline
Joined: 2005-05-06
Points: 0

Check this file with OPJViewer JPEG 2000 Viewer if it has correct blocks defined.

http://drake.diei.unipg.it/software/opjviewer_jpeg_2000_viewer

budait
Offline
Joined: 2009-07-08
Points: 0

THX. I checked the image using this tool and it seems that no code blocks contain error. Can someone help me further?

miclom
Offline
Joined: 2009-07-02
Points: 0

photo in opjviewer_jpeg_2000_viewer looks fine, btw i use now:

jai_imageio1.2
jai_codec-1.1.3.jar
jai_core-1.1.3.jar

and all works. But my modificated jai_imageio logs some problem with box in your photo - some box length have value < 0. So try in other photo.

My logs (can compare with value in openJPEG viewer)

--data from CodeStreamBox
Pos=77, len=14658
JPEG2000CodeStreamBox, getTypeString=jp2c

--wrong data len<0
Pos=14735, len=-1771031965

jai_imageio doesn't secure if your box has mistake length value (very big as mentioned in post above or < 0), so if photo is created by someone application with mistake there can error apper.

Message was edited by: miclom

miclom
Offline
Joined: 2009-07-02
Points: 0

Problem with photo occured, cuz somebody made mistake in metadata blocks. Sorry for disturbing.

marksmys
Offline
Joined: 2005-05-06
Points: 0

Yes, this is true. Four block have unknown identifier ?aVb with size 14405 > 965 159 372. This is absolutly invalid, but JAI should ignore unknown identifier or throw exception about wrong identifier. Additional OutOffMemory Error is higher problem, there is easy to prepare invalid image with wrong block container size like this and kill whole server for example or application.

marksmys
Offline
Joined: 2005-05-06
Points: 0

After update jai-imageio to 1.2-pre-dr-b04 and jai-core to 1.3 image is properly readed and converted but this small image need -Xms1536m to run. Without this there is error:

Decoding Java Advanced Imaging Image I/O Tools natively-accelerated JPEG 2000 Image Reader
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at com.sun.medialib.codec.jp2k.Decoder.decodeBox(Decoder.java:277)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.readImageMetadata(J2KRenderedImageCodecLib.java:969)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.createOriginalSampleModel(J2KRenderedImageCodecLib.java:673)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.(J2KRenderedImageCodecLib.java:261)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLib.read(J2KImageReaderCodecLib.java:364)
at javax.imageio.ImageReader.read(ImageReader.java:923)
...

marksmys
Offline
Joined: 2005-05-06
Points: 0

When using Java Advanced Imaging Image I/O Tools natively-accelerated JPEG 2000 Image Reader there is another error on this image file:

java.lang.NullPointerException
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KMetadata.replace(J2KMetadata.java:962)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KMetadata.addNode(J2KMetadata.java:631)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.readImageMetadata(J2KRenderedImageCodecLib.java:1006)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.createOriginalSampleModel(J2KRenderedImageCodecLib.java:673)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.(J2KRenderedImageCodecLib.java:261)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLib.read(J2KImageReaderCodecLib.java:364)
at javax.imageio.ImageReader.read(ImageReader.java:923)
...

marksmys
Offline
Joined: 2005-05-06
Points: 0

Link to image file
http://savefile.com/files/2144577
http://www.filefactory.com/file/aha5c24/n/5440000000011278_ZIC_jpeg2000
JAI throws exception when reading it, other viewers open this image without problems.

marksmys
Offline
Joined: 2005-05-06
Points: 0