JDK-6444933 : ImageIO creates faulty images of certain standard JPG files
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 1.4.2,5.0,6u10,7,7u10
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS:
    generic,windows_2000,windows_xp,windows_vista generic,windows_2000,windows_xp,windows_vista
  • CPU: generic,x86
  • Submitted: 2006-06-29
  • Updated: 2020-08-11
  • Resolved: 2020-05-04
Related Reports
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version " 1.5.0_06"
java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows XP Service Pack 2

A DESCRIPTION OF THE PROBLEM :
Java ImageIO reads certain JPG files and generates faulty images looking like a red-filter has been applied.
These JPEGS work fine using other Imaging-Applications like IRFANVIEW, Photoshop etc. and are also displayed correctly in any browser.

Even using the "old" java way, using the Toolkit Classes works fine (java.awt.Toolkit.getDefaultToolkit().createImage(...) ).

Just Java ImageIO produces these red images.
This problem seems to be a similar one as bug #4881314, but is not fixed in 1.5.0_04 as mentioned there.

This also occurs with:
J2SE 1.4.1_06 on Windows XP
J2SE 1.4.2_06 on Windows XP
J2SE 1.5.0_03 on Windows XP
and with latest release as mentioned above
J2SE 1.5.0_06 on Windows XP


The code necessary to reproduce this behaviour looks like:

File f = new File("W:/java/ImageIORedColored-1.jpg");
//File f = new File("W:/java/ImageIORedColored-2.jpg");
BufferedImage bi = ImageIO.read(f);

JFrame f = new JFrame();
JLabel l = new JLabel(new ImageIcon(bi));
f.setContentPane(l);
f.pack();
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setVisible(true);


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Examples of affected JPEGs can be found here:
http://cobra.levigo.de/java/ImageIORedColored-1.jpg and
http://cobra.levigo.de/java/ImageIORedColored-2.jpg

Start the appended JPEG_Test Demo application.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The generated image should have the correct colors.
ACTUAL -
The generated image looks if a red filter has been applied.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error messages

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class JPEG_Test extends JFrame{
	
	JPEG_Test(){
	super("ImageIO JPEG Test");
		
  	File f = new File("W:/java/ImageIORedColored-1.jpg");
//  	File f = new File("W:/java/ImageIORedColored-2.jpg");
  	BufferedImage bi = null;
  	try {
	  bi = ImageIO.read(f);
	} catch (IOException e) {
	  e.printStackTrace();
	}

    JLabel l = null;
    if (bi != null)
    	l = new JLabel(new ImageIcon(bi));
    else
    	l = new JLabel("Problems occured.");
    
    setContentPane(l);
    pack();
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setVisible(true);
}
	
public static void main(String[] args) {
   new JPEG_Test();
}
}
---------- END SOURCE ----------

Comments
This does not reproduce with recent JDK versions. This reproduces with 8u60 but not with 8121. (I attached the original images from the submitter). In 8u92 we backported the JDK 9 fix :- https://bugs.openjdk.java.net/browse/JDK-8041501 which addresses exactly this problem, so this is a dup.
04-05-2020

RULE 2D_ImageIO/AutoPushbackFCIISTest ExitCode 255 RULE 2D_ImageIO/AutoPushbackMCIISTest ExitCode 255
25-11-2014

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)
14-03-2014

EVALUATION This problem is caused by an heuristic introduced (or restored) by fix for CR 4776576, which makes an assumptions about image color space based on the color component subsampling. The test cases form this CR show that this heuristic is wrong and we can not derive the color space form the subsampling. I suggest to remove the heuristic to resolve this problem: we should make decision about image color space by using color component description from SOF marker or/and by presence or absence of any markers defining the color space (like APP0 JFIF or APP1 EXIF). Note that this remove will cause failure of regression test for 4776576. However, image used in the test for 4776576 is incorrect and third-party applications show it with wrong (or, that would be more correct, unexpected) colors, because it contains RGB data but YCbCr color component description in the SOF marker. I believe that we should handle it accordingly. The test case for 4712797 will work fine without this heuristic, because it contains APP1 marker and correct components description in the SOF marker.
19-12-2008