Fix mask parameters loop problem
diff --git a/src/main/java/org/apache/commons/imaging/formats/bmp/PixelParserBitFields.java b/src/main/java/org/apache/commons/imaging/formats/bmp/PixelParserBitFields.java
index 42f7ac8..5512f28 100644
--- a/src/main/java/org/apache/commons/imaging/formats/bmp/PixelParserBitFields.java
+++ b/src/main/java/org/apache/commons/imaging/formats/bmp/PixelParserBitFields.java
@@ -55,6 +55,10 @@
}
private int getMaskShift(int mask) {
+ if (mask == 0) {
+ return 0;
+ }
+
int trailingZeroes = 0;
while ((0x1 & mask) == 0) {
diff --git a/src/test/data/images/bmp/5/@broken/timeout-bd15dbfa26b4e88070de540c6603039e8a88626f b/src/test/data/images/bmp/5/@broken/timeout-bd15dbfa26b4e88070de540c6603039e8a88626f
new file mode 100644
index 0000000..77621fa
--- /dev/null
+++ b/src/test/data/images/bmp/5/@broken/timeout-bd15dbfa26b4e88070de540c6603039e8a88626f
Binary files differ
diff --git a/src/test/java/org/apache/commons/imaging/formats/bmp/BmpReadTest.java b/src/test/java/org/apache/commons/imaging/formats/bmp/BmpReadTest.java
index 0d22290..a5500d4 100644
--- a/src/test/java/org/apache/commons/imaging/formats/bmp/BmpReadTest.java
+++ b/src/test/java/org/apache/commons/imaging/formats/bmp/BmpReadTest.java
@@ -28,6 +28,9 @@
import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.Imaging;
+import org.apache.commons.imaging.ImagingTest;
+import org.apache.commons.imaging.ImagingTestConstants;
+import org.apache.commons.imaging.common.bytesource.ByteSourceFile;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -68,4 +71,17 @@
// TODO assert more
}
+ /**
+ * Test that when the value of the mask parameter is zero, getMaskShift won't
+ * get stuck in one of its while loops.
+ *
+ * @throws IOException
+ * @throws ImageReadException
+ */
+ @Test(timeout = 1000)
+ public void testGetMaskShiftZeroMask() throws ImageReadException, IOException {
+ File inputFile = new File(ImagingTestConstants.TEST_IMAGE_FOLDER +
+ "/bmp/5/@broken/timeout-bd15dbfa26b4e88070de540c6603039e8a88626f");
+ new BmpImageParser().dumpImageFile(new ByteSourceFile(inputFile));
+ }
}