JDK-4919031 : LookOp.filter() crashes VM when attempt to filter CMYK jpeg.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.0,5.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: solaris_8,windows_xp
  • CPU: x86,sparc
  • Submitted: 2003-09-08
  • Updated: 2014-03-18
Related Reports
Duplicate :  
Description
Start the program below with the attached .jpg file as input and any name as output. The VM will crash. The log of crash attached. Problem reproducible on
JDK 1.4.0, 1.4.2 and current sources.

import javax.imageio.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.color.ColorSpace;
import java.io.*;
import java.util.*;

public class ImageInvertor
{
    public static void main( String[] args )
        throws IOException
    {
        if ( args.length != 2 ) {
            System.out.println( "Usage is: ImageInvertor <inFile.jpg> <outFile.jpg>" );
            return;
        }
        long startTime = System.currentTimeMillis();

        String inFileName  = args[0];
        System.out.println(inFileName);
        String outFileName = args[1];

        // read
        BufferedImage img = ImageIO.read( new BufferedInputStream( new FileInputStream( inFileName ) ) );
        if ( img == null )
            throw new IOException( "File format is unknown" );

        BufferedImage oimg = 
            new BufferedImage( img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB );

        byte invert[] = new byte[256];
        for (int j = 0; j < 256 ; j++) {
            invert[j] = (byte) (256-j);
        }
        LookupOp lop = new LookupOp( new ByteLookupTable( 0, invert ), null );

        lop.filter( img, oimg );


        // write
        OutputStream out = new BufferedOutputStream( new FileOutputStream( outFileName ) );
        try {
            ImageIO.write( oimg, "JPEG", out );
        }
        finally {
            out.close();
        }

        System.out.println( "Time consumed: " + ( System.currentTimeMillis() - startTime ) + "ms" );
   }
}

Comments
Please re-open if - if fix is in progress or on the plan to fix soon - if this is a P3 (file as P3, not P4)
18-03-2014

EVALUATION Due to ImageIO plugins limitation the CMYK image is not recognized and custom RGB image is created (namely, is is INT_RGBA). The awt_parseImage() does not properly initialize helper colorOrder array for such kind of custom buffered images. Note that this helper array is used by medialib gluecode to re-arange the lookup table according to the detected image color order. The elements of the colorOrder array are used as indices in the updated lookup table and incorrect value of colorOrder elements (greater than number of image components) can cause array overrun and leads to memory corruption and crash.
08-12-2006