Description
Firstly I apologize this does not follow the bug report layout, nor can be reproduced with only libjpeg-turbo, but I found some old fixes in libjpeg-turbo which refer to a similar problem.
I am trying to find out where to look to further debug the following:
Using the Java OpenJDK 11 or up (not yet JDK 8), using ImageIO to open a JPEG file throws for certain files the following error:
Exception in thread "main" javax.imageio.IIOException: Bogus virtual array access
at java.desktop/com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
at java.desktop/com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1318)
at java.desktop/com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:1110)
at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1468)
at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1315)
at ImageExceptionMain.main(ImageExceptionMain.java:10)
where readNative
is in the JVM's own libjavajpeg.so
which uses libjpeg-turbo, currently version 2.1.3.
This happens on both FreeBSD and Arch Linux builds of OpenJDK, both of which default to using the system jpeg library (libjpeg-turbo version 2.1.3)
If I compile the JDK with --libjpeg=bundled
, which uses a jpeg reference implementation, everything works fine.
It is easy to reproduce from Java, please see the java source code below and an example image file (no affiliation to its contents!)
I could not reproduce any problem with the standard libjpeg-turbo binaries themselves, so again apologies if this has nothing to do with libjpeg-turbo itself.
To reproduce create ImageExceptionMain.java
with the following contents:
import java.io.File;
import java.io.IOException;
import javax.imageio.*;
import java.awt.image.BufferedImage;
public class ImageExceptionMain {
public static void main(String[] args) throws IOException {
BufferedImage image = ImageIO.read(new File("image.jpg"));
}
}
and run
javac ImageExceptionMain.java && java ImageExceptionMain
with an OpenJDK version 11 or 17 that was compiled with system-jpeg libraries.
with the following image file (I hope github does not modify it in some way):
but just in case it does here it is attached as a zipped file: