Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4996204
Votes 1
Synopsis The TIFF codec sometimes throws an IllegalArgumentException
Category jai:codec_sample
Reported Against 1.1.1
Release Fixed 1.1.3
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs
Submit Date 18-FEB-2004
Description


FULL PRODUCT VERSION :
Under Solaris:

java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

Under Linux:

java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
SunOS cad001sv 5.8 Generic_108528-14 sun4u sparc SUNW,UltraAX-i2

Also reproducible under Linux (and I assume, Windows as well):

Linux sparrow 2.4.20-24.9 #1 Mon Dec 1 11:35:51 EST 2003 i686 i686 i386 GNU/Linux

EXTRA RELEVANT SYSTEM CONFIGURATION :
Nothing relevant.

A DESCRIPTION OF THE PROBLEM :
The TIFF codec throws an IllegalArgumentException when determining the number of pages in some TIFFs (the TIFFs in question appear to be corrupt).  Even though the files in question are corrupt the TIFF codec should not be throwing a RuntimeException!  At the very least, if you guys feel it is valid for the codec to be throwing a RuntimeException when a file is corrupt it should be documented.  I've tested this behavior with the codec bundled with JAI v1.1.1 & v1.1.2, both exhibit the same bug.

I can provide several corrupt tiff files that cause this behavior.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test case below on a corrupt tiff file...



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
In the case of a corrupt tiff I was expecting either an IOException to be thrown or simply -1 to be returned.  The javadoc isn't clear what the behavior will be in the case of a corrupted file.
ACTUAL -
An IllegalArgumentException (RuntimeException) resulting in an application crash.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.IllegalArgumentException: Bad endianness tag (not 0x4949 or 0x4d4d).
	at com.sun.media.jai.codec.TIFFDirectory.getNumDirectories(TIFFDirectory.java:588)
	at com.sun.media.jai.codecimpl.TIFFImageDecoder.getNumPages(TIFFImageDecoder.java:105)
	at com.kelman.testcase.TiffCodecBug.main(TiffCodecBug.java:42)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package com.kelman.testcase;

import java.io.File;
import java.io.IOException;

import com.sun.media.jai.codec.FileSeekableStream;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.SeekableStream;
import com.sun.media.jai.codec.TIFFDecodeParam;

/**
* This class determines the number of pages in a tiff file using
* the tiff codec included with JAI.  You will have to have the
* jai_codec.jar (part of the JAI v1.1.2 distribution) on the classpath.
*
* When given a corrupt tiff file the getNumPage() call throws an
* IllegalArgumentException.
* 
* @author corey
**/
public class TiffCodecBug
{

  /**
  * Run with a single argument: the filename of the tiff file...
  * <P>
  * @param args
  **/
  public static void main(String[] args)
  {
    File tiffFile = new File(args[0]);
    SeekableStream s = null;
    int pages = -1;

    try
    {
      s = new FileSeekableStream(tiffFile);

      TIFFDecodeParam param = null;
      ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param);
      pages = dec.getNumPages();
      System.out.println("This tiff image contains " + pages + " pages.");
    }
    catch(IOException ioex)
    {
      System.err.println(ioex);
      System.exit(1);
    }
    finally
    { if (s != null) try { s.close(); } catch(IOException ioex) {} }
  }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
The workaround is to catch RuntimeException...
(Incident Review ID: 236181) 
======================================================================
Posted Date : 2006-06-21 00:21:14.0
Work Around
N/A
Evaluation
  xxxxx@xxxxx   2004-02-18

RuntimeExceptions are thrown as described but in TIFFDirectory.
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang