Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.0-alpha2
-
None
-
None
Description
The following Java snippet crashes with an ArrayIndexOutOfBoundsException:
import java.io.IOException; import java.util.Base64; import java.util.HashMap; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.common.bytesource.ByteSourceArray; import org.apache.commons.imaging.formats.tiff.TiffImageParser; public class TiffImageParserCrash { public static byte[] btoa(String base64) { return Base64.getDecoder().decode(base64); } public static void main(String[] args) { byte[] input = btoa("SUkqAAoAAAACAgIAAQIIAAAAAADNAAICAgICAAAAAAAA////////CQ=="); try { new TiffImageParser().getBufferedImage(new ByteSourceArray(input), new HashMap<>()); } catch (IOException | ImageReadException e) {} } }
The stack trace is:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 at org.apache.commons.imaging.formats.tiff.TiffDirectory.getJpegRawImageDataElement(TiffDirectory.java:859) at org.apache.commons.imaging.formats.tiff.TiffReader.getJpegRawImageData(TiffReader.java:485) at org.apache.commons.imaging.formats.tiff.TiffReader.readDirectory(TiffReader.java:219) at org.apache.commons.imaging.formats.tiff.TiffReader.readDirectory(TiffReader.java:115) at org.apache.commons.imaging.formats.tiff.TiffReader.readDirectories(TiffReader.java:108) at org.apache.commons.imaging.formats.tiff.TiffReader.read(TiffReader.java:419) at org.apache.commons.imaging.formats.tiff.TiffReader.readFirstDirectory(TiffReader.java:382) at org.apache.commons.imaging.formats.tiff.TiffImageParser.getBufferedImage(TiffImageParser.java:465) at TiffImageParserCrash.main(TiffImageParserCrash.java:17)