This is an automated email from the ASF dual-hosted git repository. kinow pushed a commit to branch release in repository https://gitbox.apache.org/repos/asf/commons-imaging.git
commit 601fea58c7402658d821bdbe754e08eb19c95e82 Author: Bruno P. Kinoshita <ki...@apache.org> AuthorDate: Sat Apr 27 23:14:50 2019 +1200 Fix mask parameters loop problem --- .../imaging/formats/bmp/PixelParserBitFields.java | 4 ++++ .../timeout-bd15dbfa26b4e88070de540c6603039e8a88626f | Bin 0 -> 128 bytes .../apache/commons/imaging/formats/bmp/BmpReadTest.java | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) 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 @@ class PixelParserBitFields extends PixelParserSimple { } 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 Binary files /dev/null and b/src/test/data/images/bmp/5/@broken/timeout-bd15dbfa26b4e88070de540c6603039e8a88626f 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 java.util.Map; 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 @@ public class BmpReadTest extends BmpBaseTest { // 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)); + } }