[IMAGING-279] add unit test with user-provided image
diff --git a/src/test/java/org/apache/commons/imaging/formats/bmp/BmpImageParserTest.java b/src/test/java/org/apache/commons/imaging/formats/bmp/BmpImageParserTest.java
index 13ef1d8..d3dc7e3 100644
--- a/src/test/java/org/apache/commons/imaging/formats/bmp/BmpImageParserTest.java
+++ b/src/test/java/org/apache/commons/imaging/formats/bmp/BmpImageParserTest.java
@@ -17,6 +17,7 @@
package org.apache.commons.imaging.formats.bmp;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.File;
import java.io.IOException;
@@ -45,4 +46,19 @@
final ImageInfo imageInfo = parser.getImageInfo(bmp, Collections.emptyMap());
assertEquals(73, imageInfo.getPhysicalWidthDpi(), "Expected 72.6 resolution to be rounded to 73");
}
+
+ /**
+ * For https://issues.apache.org/jira/browse/IMAGING-279.
+ * @throws IOException
+ * @throws ImageReadException
+ */
+ @Test
+ public void testImageForNegativeArraySizeException() throws ImageReadException, IOException {
+ final String file = "/images/bmp/IMAGING-279/negative_array_size_exception.bmp";
+ final File bmp = new File(BmpImageParser.class.getResource(file).getFile());
+ final BmpImageParser parser = new BmpImageParser();
+ assertThrows(IOException.class, () -> {
+ parser.getImageInfo(bmp, Collections.emptyMap());
+ });
+ }
}
diff --git a/src/test/resources/images/bmp/IMAGING-279/negative_array_size_exception.bmp b/src/test/resources/images/bmp/IMAGING-279/negative_array_size_exception.bmp
new file mode 100644
index 0000000..7a33b86
--- /dev/null
+++ b/src/test/resources/images/bmp/IMAGING-279/negative_array_size_exception.bmp
Binary files differ