Skip to main content

ArrayIndexOutOfBoundsException reading TIFF image

12 replies [Last post]
willishf
Offline
Joined: 2006-02-12

Trying to track down the source of the problem File or Code when loading a fax image. The tiff file loads correctly in the default windows viewer. The intial fax was 30 and 24 pages and both had problems. We have not had any problems with 3 or 4 page faxes. I deleted all the pages except the first one which reads correctly and the second page which creates the error. We have had 100+ faxes tested and didn't run into the problem with bad pages until now so I feel it is probably something in the tiff image that is in or out of spec and JAI is not handling it. I can email the file that is creating the problem if somebody from the JAI has better testing tools for loading tiff images that may or may not have hearder problems. Send me an email willishf@ufl.edu if you would like to test with the file. I opened a support case via the sun site for JAI but the only versions to select were 1.1.X so I imagine it is not in use. The problem occurs in both the 1.3 latest release and the prior version.

The code segment which throws an exception at ria.getAsBufferedImage(); and the exception

RenderedImage op = new NullOpImage(dec.decodeAsRenderedImage(imageToLoad),null,OpImage.OP_IO_BOUND,null);
elapsedTime("End decodeAsRenderedImage");
TIFFDirectory tiffDirectory = (TIFFDirectory)op.getProperty("tiff_directory");
TIFFField[] tiffFields = tiffDirectory.getFields();
for(int i = 0; i < tiffFields.length; i++){
if(tiffFields[i].getTag() == 282){ // looking for X Resolution
long[][] data = tiffFields[i].getAsRationals();
xResolution = (int)data[0][0];
}else if(tiffFields[i].getTag() == 283){ //looking for Y Resolution
long[][] data = tiffFields[i].getAsRationals();
yResolution = (int)data[0][0];
}
}

docInfo.resolution = yResolution;

elapsedTime("Start RenderedImageAdapter");
RenderedImageAdapter ria = new RenderedImageAdapter(op);
elapsedTime("End RenderedImageAdapter");

elapsedTime("Start getAsBufferedImage");
BufferedImage bi = ria.getAsBufferedImage();

***********************************************

java.lang.ArrayIndexOutOfBoundsException: 27295
at com.sun.media.jai.codecimpl.TIFFFaxDecoder.nextLesserThan8Bits(TIFFFaxDecoder.java:1484)
at com.sun.media.jai.codecimpl.TIFFFaxDecoder.decodeNextScanline(TIFFFaxDecoder.java:647)
at com.sun.media.jai.codecimpl.TIFFFaxDecoder.decode2D(TIFFFaxDecoder.java:879)
at com.sun.media.jai.codecimpl.TIFFImage.getTile(TIFFImage.java:1071)
at javax.media.jai.RenderedImageAdapter.getTile(RenderedImageAdapter.java:148)
at javax.media.jai.NullOpImage.computeTile(NullOpImage.java:162)
at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
at javax.media.jai.OpImage.getTile(OpImage.java:1129)
at javax.media.jai.PlanarImage.copyData(PlanarImage.java:2343)
at javax.media.jai.RenderedImageAdapter.copyData(RenderedImageAdapter.java:163)
at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2525)
at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2546)
at edu.ufl.bridges.fax.MultiPageReadDataMatrix.processTiffImage(MultiPageReadDataMatrix.java:212)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rahul_b_bandgar
Offline
Joined: 2006-12-11

from where to download jai_imageio.jar and clibwrapper_jiio.jar ?

Brian Burkhalter

https://jai-imageio.dev.java.net

"Downloads"

On Mon, 11 Dec 2006, jai-interest@javadesktop.org wrote:

> from where to download jai_imageio.jar and clibwrapper_jiio.jar ?
> [Message sent by forum member 'rahul_b_bandgar' (rahul_b_bandgar)]
>
> http://forums.java.net/jive/thread.jspa?messageID=184864
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Brian Burkhalter

Please go ahead and mail the file directly.

By the way, you'd probably be better off using the JAI Image I/O Tools TIFF
plug-ins.

Brian

On Wed, 27 Sep 2006, jai-interest@javadesktop.org wrote:

> Trying to track down the source of the problem File or Code when loading a fax image. The tiff file loads correctly in the default windows viewer. The intial fax was 30 and 24 pages and both had problems. We have not had any problems with 3 or 4 page faxes. I deleted all the pages except the first one which reads correctly and the second page which creates the error. We have had 100+ faxes tested and didn't run into the problem with bad pages until now so I feel it is probably something in the tiff image that is in or out of spec and JAI is not handling it. I can email the file that is creating the problem if somebody from the JAI has better testing tools for loading tiff images that may or may not have hearder problems. Send me an email willishf@ufl.edu if you would like to test with the file. I opened a support case via the sun site for JAI but the only versions to select were 1.1.X so I imagine it is not in use. The problem occurs in both the 1.3 latest release and the prior version.
>
> The code segment which throws an exception at ria.getAsBufferedImage(); and the exception
>
> RenderedImage op = new NullOpImage(dec.decodeAsRenderedImage(imageToLoad),null,OpImage.OP_IO_BOUND,null);
> elapsedTime("End decodeAsRenderedImage");
> TIFFDirectory tiffDirectory = (TIFFDirectory)op.getProperty("tiff_directory");
> TIFFField[] tiffFields = tiffDirectory.getFields();
> for(int i = 0; i < tiffFields.length; i++){
> if(tiffFields[i].getTag() == 282){ // looking for X Resolution
> long[][] data = tiffFields[i].getAsRationals();
> xResolution = (int)data[0][0];
> }else if(tiffFields[i].getTag() == 283){ //looking for Y Resolution
> long[][] data = tiffFields[i].getAsRationals();
> yResolution = (int)data[0][0];
> }
> }
>
> docInfo.resolution = yResolution;
>
> elapsedTime("Start RenderedImageAdapter");
> RenderedImageAdapter ria = new RenderedImageAdapter(op);
> elapsedTime("End RenderedImageAdapter");
>
> elapsedTime("Start getAsBufferedImage");
> BufferedImage bi = ria.getAsBufferedImage();
>
>
> ***********************************************
>
> java.lang.ArrayIndexOutOfBoundsException: 27295
> at com.sun.media.jai.codecimpl.TIFFFaxDecoder.nextLesserThan8Bits(TIFFFaxDecoder.java:1484)
> at com.sun.media.jai.codecimpl.TIFFFaxDecoder.decodeNextScanline(TIFFFaxDecoder.java:647)
> at com.sun.media.jai.codecimpl.TIFFFaxDecoder.decode2D(TIFFFaxDecoder.java:879)
> at com.sun.media.jai.codecimpl.TIFFImage.getTile(TIFFImage.java:1071)
> at javax.media.jai.RenderedImageAdapter.getTile(RenderedImageAdapter.java:148)
> at javax.media.jai.NullOpImage.computeTile(NullOpImage.java:162)
> at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
> at javax.media.jai.OpImage.getTile(OpImage.java:1129)
> at javax.media.jai.PlanarImage.copyData(PlanarImage.java:2343)
> at javax.media.jai.RenderedImageAdapter.copyData(RenderedImageAdapter.java:163)
> at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2525)
> at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2546)
> at edu.ufl.bridges.fax.MultiPageReadDataMatrix.processTiffImage(MultiPageReadDataMatrix.java:212)
> [Message sent by forum member 'willishf' (willishf)]
>
> http://forums.java.net/jive/thread.jspa?messageID=157243
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

willishf
Offline
Joined: 2006-02-12

I sent the file to jai-interest@javadesktop.org

It is a little confusing as to what version of what project is included in the parent project etc. I assumed that they are shared a common code base.

Can you point me to the URL/download for the JAI Image I/O tools. I will also try and sort my way which is the project to download. I thought I had made that mistake before and for some reason I was missing a Jar file. I will revisit and will test tomorrow.

Thanks

Scooter Willis

Brian Burkhalter

On Wed, 27 Sep 2006, jai-interest@javadesktop.org wrote:

> I sent the file to jai-interest@javadesktop.org

That won't work: attachments are stripped I think.

> It is a little confusing as to what version of what project is included in the parent project etc. I assumed that they are shared a common code base.

This page is a little stale but is essentially correct:

http://java.sun.com/products/java-media/jai/iio.html

> Can you point me to the URL/download for the JAI Image I/O tools. I will also try and sort my way which is the project to download. I thought I had made that mistake before and for some reason I was missing a Jar file. I will revisit and will test tomorrow.

Try this:

https://jai-imageio.dev.java.net/binary-builds.html

Brian

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

willishf
Offline
Joined: 2006-02-12

Can you send me the email address that I should use to send the file directly? willishf@ufl.edu

Not sure how to deliver the file.

Brian Burkhalter

You shold have the address now ...

On Wed, 27 Sep 2006, jai-interest@javadesktop.org wrote:

> Can you send me the email address that I should use to send the file directly? willishf@ufl.edu
>
> Not sure how to deliver the file.

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

willishf
Offline
Joined: 2006-02-12

One step forward one step back.

I downloaded and installed the stable version JAI-ImageIO for JDK jai_imageio-1_1-beta-lib-windows-i586-jdk.exe. I am using netbeans and added to the project in jai_imageio.jar and clibwrapper_jiio.jar from the jre\lib\ext directory.

I could not find any solid examples of what I needed to setup for development so may be missing something.

I manage to find some sample code from a posting on how to read a tiff image. Running the following with the bad tif image created more than one crash of the VM but then it ran okay another 10 times without crashing.

Any thoughts on the nature of the problem? Do you have a good code example for reading tiff images and determing some of the header information. I need to rescale the images based on the resolution used when sending the fax.

String inPath = "C:/NetBeansProjects/Barcode/images/000056ec-badpage.tif"; //00004fef.tif; //000056ec-badpage.tif";
RenderedImage src = ImageIO.read(new File(inPath));
Iterator readers = ImageIO.getImageReadersByFormatName("tiff");
if(readers == null || !readers.hasNext()) {
throw new RuntimeException("No readers for "+inPath);
}
ImageReader reader = (ImageReader)readers.next();
ImageInputStream input = ImageIO.createImageInputStream(new File(inPath));
reader.setInput(input);

BufferedImage bi = reader.read(0);

#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c911e58, pid=2684, tid=2688
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode)
# Problematic frame:
# C [ntdll.dll+0x11e58]
#
# An error report file with more information is saved as hs_err_pid2684.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#

willishf
Offline
Joined: 2006-02-12

Not sure if I restarted netbeans after the install of jai_imageio. I restarted and it seems better. Not sure where the problem was but will be doing more testing tomorrow.

I also found the very handy .getAspectRatio() method which is what I need to resize images.

willishf
Offline
Joined: 2006-02-12

Didn't take long

Change the code a bit and added in looping through all the images and get the following VM crash

try{
String inPath = "C:/NetBeansProjects/Barcode/images/000056ec.tif"; //00004fef.tif; //000056ec-badpage.tif";

//RenderedImage src = ImageIO.read(new File(inPath));

Iterator readers = ImageIO.getImageReadersByFormatName("tiff");

if(readers == null || !readers.hasNext()) {
throw new RuntimeException("No readers for "+inPath);
}

ImageReader reader = (ImageReader)readers.next();

ImageInputStream input = ImageIO.createImageInputStream(new File(inPath));

reader.setInput(input);

int numImages = reader.getNumImages(true);
System.out.println("Number of pages " + numImages);
for(int i = 0; i < numImages; i++){
System.out.println(i + " aspect ratio " + reader.getAspectRatio(i));
BufferedImage bi = reader.read(i);
}
reader.dispose();
input.close();

// Create the read param.
//TIFFImageReadParam readParam = new TIFFImageReadParam();
//readParam.setTIFFDecompressor(new TIFFNotDecompressor());

// Read the image.
//RenderedImage image = reader.read(0, readParam);
}catch(Exception e){
System.out.println(e);
}

Number of pages 31
0 aspect ratio 1.605948
1 aspect ratio 1.605948
2 aspect ratio 1.605948
3 aspect ratio 1.605948
4 aspect ratio 1.605948
5 aspect ratio 1.605948
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c911e58, pid=3364, tid=6072
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode)
# Problematic frame:
# C [ntdll.dll+0x11e58]
#
# An error report file with more information is saved as hs_err_pid3364.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#

willishf
Offline
Joined: 2006-02-12

I just realized that I was posting in JAI not JAI-imageio. When I moved over I saw the posting about the daily build and VM crashing. Added in the new jar and libs and the code is now working.

Two step forward and thanks for the help and of course the code. Now I have a bit of rewriting to do and more testing of our main application.

Brian Burkhalter

Glad to hear that all appears to be working now. Please let us know should
encounter any more such errors. If such do appear and we are unable to fix
them before the 1.1 release then you can disable the native code as described
here:

http://download.java.net/media/jai-imageio/javadoc/1.1-latest/overview-s...

Brian

On Wed, 27 Sep 2006, jai-interest@javadesktop.org wrote:

> I just realized that I was posting in JAI not JAI-imageio. When I moved over I saw the posting about the daily build and VM crashing. Added in the new jar and libs and the code is now working.
>
> Two step forward and thanks for the help and of course the code. Now I have a bit of rewriting to do and more testing of our main application.

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net