Ubuntu

ImageIO crashes (core dumped) while reading many image files

Reported by Joshua Rocky Tuahta Purba on 2012-01-08
38
This bug affects 7 people
Affects Status Importance Assigned to Milestone
openjdk-7 (Ubuntu)
Undecided
Unassigned

Bug Description

Code that uses ImageIO.read() to read many image files (on my system: 270 files, totalling 522.9 MiB) crashes the JVM.

~~~ My system information:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 11.10
Release: 11.10
Codename: oneiric

$ uname -a
Linux dowah 3.0.0-14-generic #23-Ubuntu SMP Mon Nov 21 20:28:43 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

$ javac -version
javac 1.7.0_147

$ java -version
java version "1.7.0_147-icedtea"

~~~ To reproduce the error:

$ javac BugIIO.java

$ ulimit -c unlimited # to enable core dump

$ java BugIIO

~~~ Terminal output that signifies the error:

#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fb5babe31f8, pid=4978, tid=140418842154752
#
# JRE version: 7.0_147-b147
# Java VM: OpenJDK 64-Bit Server VM (21.0-b17 mixed mode linux-amd64 compressed oops)
# Derivative: IcedTea7 2.0
# Distribution: Ubuntu 11.10, package 7~b147-2.0-0ubuntu0.11.10.1
# Problematic frame:
# C [liblcms2.so.2+0x121f8] cmsSaveProfileToIOhandler+0x38
#
# Core dump written. Default location: /home/joshua/core or core.4978
#
# An error report file with more information is saved as:
# /home/joshua/hs_err_pid4978.log
#
# If you would like to submit a bug report, please include
# instructions on how to reproduce the bug and visit:
# https://bugs.launchpad.net/ubuntu/+source/openjdk-7/
#
Dibatalkan (core didump)

~~~ PS
When I tried to compile BugIIO.java on openjdk-6 and run it on openjdk-6, the program finishes normally (no crash).

To clarify:
1. This bug affect OpenJDK 7 (7~b147-2.0-0ubuntu0.11.10.1) (tested on oneiric).
2. This bug does *not* affect OpenJDK 6 (6b23~pre11-0ubuntu1.11.10) (tested on oneiric).

Here is the "error report file" (hs_err_pid4978.log) from this step (as described above):

$ java BugIIO

Here is the "core dump" (xz compressed, uncompress before use) from this step (as described above):

$ java BugIIO

description: updated
description: updated
description: updated
description: updated

I have just found out that, using BufferedInputStream - instead of java.io.File - as parameter for ImageIO.read() will not cause core dump. This probably means that there is something wrong with the code in ImageIO.read() that cause crash while reading from java.io.File.

P.S. the difference between NonBugIIO.java and BugIIO.java, is that the BugIIO.java uses File as parameter for ImageIO.read(), while NonBugIIO.java uses BufferedInputStream as parameter for ImageIO.read().

Vova Zoubritsky (vogre-z) wrote :

I was lucky(?) enough to find a single image which causes the crash for me (running on a 1Gb folder of other images did nothing), however, it must be said that the crash doesn't always happen ib the same way:

1) Running the minimal Java code (BugIIO.java/NoBugIIO.java) causes an exception: java.lang.IllegalArgumentException: Can't load standard profile: sRGB.pf.
2) Running the minimal code with sbt (which loads the class dynamically) loads the image fine and does not have an exception.
3) Using the same image in different points of my program (I can attach it as well) causes either the "Can't load standard profile" exception or a crash at sun.java2d.cmm.lcms.LCMS.getTagData(JI[B)V+0 (same as original report).

Using other images (without sRGB profile - checked with exiftool) or openjdk6 does not cause crashes or exceptions.

Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in openjdk-7 (Ubuntu):
status: New → Confirmed
Hendy Irawan (ceefour) wrote :

Still happens on Ubuntu 12.04, tested i386

java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.1pre) (7~u3-2.1.1~pre1-1ubuntu3)
OpenJDK Client VM (build 22.0-b10, mixed mode, sharing)

Carlo (john23) wrote :

Happens on ubuntu 12.04 x64 too.

java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.1pre) (7~u3-2.1.1~pre1-1ubuntu3)
OpenJDK 64-Bit Server VM (build 22.0-b10, mixed mode)

I've found this issue happens intermitently on my setup:
Ubuntu 13.04 64-bit
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.13.04.2)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

I get an intermitent crash when decoding JPEGs, decoding in several threads.

Thread pool is created thus:
 ExecutorService threadpool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()+1);

Image decode tasks added this:
 ImageScaler scaler = new ImageScaler(size);
 threadpool.submit(scaler);

ImageScaler class is:
 private class ImageScaler extends SwingWorker<ImageIcon, String> {
  private int size;

  public ImageScaler(int size) {
   this.size = size;
  }

  @Override
  public ImageIcon doInBackground() {
   LOGGER.log(Level.FINE,
     "Loading image: "+url);

   ImageReader ir;

   //create a new instance of imageReader
   synchronized(sync){
    Iterator<ImageReader> it = ImageIO.getImageReadersByMIMEType("image/jpeg");
    ir = it.next();
    if (ir == null) {
     LOGGER.log(Level.SEVERE,
       "No image reader found for JPEGs");
     System.exit(1);
    }
    ImageReaderSpi spi = ir.getOriginatingProvider();
    try {
     ir = spi.createReaderInstance();
    } catch (Exception e) {
     LOGGER.log(Level.SEVERE,
       "Could not create new JPEG reader instance", e);
     return null;
    }
   }

   //Load the image from the URL (could be local or HTTP)
   BufferedImage image;
   try {

[...]
    File cacheDir = new File (strCacheDir);
    cacheDir.mkdirs();
    URL u = new URL(url);
    FileCacheImageInputStream fcis = new FileCacheImageInputStream(
     u.openStream(), cacheDir);
    ir.setInput(fcis);
    image = ir.read(0);
    fcis.close();
   } catch (Exception e) {
    LOGGER.log(Level.WARNING,
      "Could not read image "+url, e);
    return null;
   } catch (OutOfMemoryError e) {
    LOGGER.log(Level.WARNING,
      "Out of memory reading image: "+url, e);
    return null;
   } finally {
    ir.dispose();
   }

   return new ImageIcon(resizeImage(image, size));
   }

  @Override
  protected void done() {
   if (isCancelled())
    return;
   ImageIcon icon = null;
   try {
    icon = get();
   } catch (Exception ignore) {}
   if (icon == null) {
    LOGGER.log(Level.WARNING,
      "Scaled image is null: "+url);
    return;
   }
   rendered = icon;
   renderedSize = size;
   mPcs.firePropertyChange(PNAME_RENDEREDICON, 0, 1);
  }

 }

The crash actually occurs in ICC_Profile code. I get intermitent colour issues with decoded JPEGs where the image is totally mid-green except for areas that are dark which tend to black. Is there an issue in the colour code for multi-threaded decode? I've done my best to create an image reader in a thread-safe way.

I've attached the crash log file.

I noticed that our crash log file points to the same "problematic frame", that is liblcms2.so.2.

From my log:

# Problematic frame:
# C [liblcms2.so.2+0x121f8] cmsSaveProfileToIOhandler+0x38

From your log:

# Problematic frame:
# C [liblcms2.so.2+0x153c5] cmsSaveProfileToIOhandler+0x35

Likewise, the java frame in our logs also have identical parts:

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j sun.java2d.cmm.lcms.LCMS.getTagData(JI[B)V+0
j java.awt.color.ICC_Profile.getData(JI)[B+26
j java.awt.color.ICC_Profile.getData(I)[B+14
j java.awt.color.ICC_Profile.getNumComponents()I+18
j sun.java2d.cmm.lcms.LCMSTransform.<init>(Ljava/awt/color/ICC_Profile;II)V+83
j sun.java2d.cmm.lcms.LCMS.createTransform(Ljava/awt/color/ICC_Profile;II)Lsun/java2d/cmm/ColorTransform;+7
j java.awt.color.ICC_ColorSpace.fromRGB([F)[F+37
j com.sun.imageio.plugins.jpeg.JPEGImageReader.setImageData(IIIII[B)V+158
v ~StubRoutines::call_stub
j com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(JZZ)Z+0
j com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(Z)Z+12
j com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly()V+92
j com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(I)V+41
j com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(IZ)V+2
j com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(ILjavax/imageio/ImageReadParam;Z)Ljava/awt/image/Raster;+3

I've just got the same crash in a slightly different bit of code (same project, but server side, not client side). The java frames from the crash log is as for the client code crash and the same as Joshua.

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j sun.java2d.cmm.lcms.LCMS.getTagData(JI[B)V+0
j java.awt.color.ICC_Profile.getData(JI)[B+26
j java.awt.color.ICC_Profile.getData(I)[B+14
j java.awt.color.ICC_Profile.getNumComponents()I+18
j sun.java2d.cmm.lcms.LCMSTransform.<init>(Ljava/awt/color/ICC_Profile;II)V+102
j sun.java2d.cmm.lcms.LCMS.createTransform(Ljava/awt/color/ICC_Profile;II)Lsun/java2d/cmm/ColorTransform;+7
j java.awt.color.ICC_ColorSpace.fromRGB([F)[F+37
j com.sun.imageio.plugins.jpeg.JPEGImageReader.setImageData(IIIII[B)V+158
v ~StubRoutines::call_stub
j com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(JZZ)Z+0
j com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(Z)Z+12
j com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly()V+92
j com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(I)V+41
j com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageMetadata(I)Ljavax/imageio/metadata/IIOMetadata;+39
j uk.co.netriver.kedarserver.CatwalkingImageProcessorTask.extractMetadata([BLjavax/imageio/ImageReader;)Ljava/util/LinkedList;+16
j uk.co.netriver.kedarserver.CatwalkingImageProcessorTask.doTask()V+623
j uk.co.netriver.kedarserver.TaskProcessor.run()V+44
j java.lang.Thread.run()V+11
v ~StubRoutines::call_stub

My server code is now throwing null pointer exceptions due to an issue in the same area (ICC colour profiles). I've been running test successfully with the same photos all morning and now they won't load at all. There has been no code change to the server. I'm guessing there's an underlying library problem.

Exception in thread "TaskProcessor" java.lang.NullPointerException
 at java.awt.color.ICC_Profile.intFromBigEndian(ICC_Profile.java:1770)
 at java.awt.color.ICC_Profile.getNumComponents(ICC_Profile.java:1462)
 at sun.java2d.cmm.lcms.LCMSTransform.<init>(LCMSTransform.java:96)
 at sun.java2d.cmm.lcms.LCMS.createTransform(LCMS.java:66)
 at java.awt.color.ICC_ColorSpace.fromRGB(ICC_ColorSpace.java:218)
 at com.sun.imageio.plugins.jpeg.JPEGImageReader.setImageData(JPEGImageReader.java:689)
 at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(Native Method)
 at com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(JPEGImageReader.java:604)
 at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly(JPEGImageReader.java:342)
 at com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(JPEGImageReader.java:476)
 at com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(JPEGImageReader.java:597)
 at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1054)
 at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:1034)
 at javax.imageio.ImageReader.read(ImageReader.java:940)

Another similar but slightly different error. Image decoded decided to stop working (no changes to code) with this exception being thrown. Was working a second ago.

WARNING: Could not read image file:/home/[...]/VALI_RTW_AW13_3026.jpg
java.awt.color.CMMException: Cannot get color transform
 at sun.java2d.cmm.lcms.LCMS.createNativeTransform(Native Method)
 at sun.java2d.cmm.lcms.LCMSTransform.doTransform(LCMSTransform.java:149)
 at sun.java2d.cmm.lcms.LCMSTransform.colorConvert(LCMSTransform.java:526)
 at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:571)
 at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(JPEGImageReader.java:1258)
 at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
 at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1226)
 at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:1034)
 at javax.imageio.ImageReader.read(ImageReader.java:940)
 at uk.co.netriver.kedarclient.data.Photo$ImageScaler.doInBackground(Photo.java:510)
 at uk.co.netriver.kedarclient.data.Photo$ImageScaler.doInBackground(Photo.java:1)
 at javax.swing.SwingWorker$1.call(SwingWorker.java:296)
 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
 at java.util.concurrent.FutureTask.run(FutureTask.java:166)
 at javax.swing.SwingWorker.run(SwingWorker.java:335)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
 at java.util.concurrent.FutureTask.run(FutureTask.java:166)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 at java.lang.Thread.run(Thread.java:724)

Katerina (katerina-andreadou) wrote :

I am getting the same error when reading many images from different URLs
BufferedImage image = ImageIO.read(myUrl);
Is there any available fix for this issue?

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j sun.java2d.cmm.lcms.LCMS.getTagData(JI[B)V+0
j java.awt.color.ICC_Profile.getData(JI)[B+26
j java.awt.color.ICC_Profile.getData(I)[B+14
j java.awt.color.ICC_Profile.getNumComponents()I+18
j sun.java2d.cmm.lcms.LCMSTransform.<init>(Ljava/awt/color/ICC_Profile;II)V+83
j sun.java2d.cmm.lcms.LCMS.createTransform(Ljava/awt/color/ICC_Profile;II)Lsun/java2d/cmm/ColorTransform;+7
j java.awt.color.ICC_ColorSpace.fromRGB([F)[F+37
j com.sun.imageio.plugins.jpeg.JPEGImageReader.setImageData(IIIII[B)V+158
v ~StubRoutines::call_stub
j com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(JZZ)Z+0
j com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(Z)Z+12
j com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly()V+92
j com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(I)V+41
j com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(IZ)V+2
j com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(ILjavax/imageio/ImageReadParam;Z)Ljava/awt/image/Raster;+3
j com.sun.imageio.plugins.jpeg.JPEGImageReader.read(ILjavax/imageio/ImageReadParam;)Ljava/awt/image/BufferedImage;+15
j javax.imageio.ImageIO.read(Ljavax/imageio/stream/ImageInputStream;)Ljava/awt/image/BufferedImage;+55
j javax.imageio.ImageIO.read(Ljava/net/URL;)Ljava/awt/image/BufferedImage;+42

I don't think there is any fix yet.

To post a comment you must log in.