This is an automated email from the ASF dual-hosted git repository.

kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git

commit 6a79d35d6654d895d0a4b73b3a9282ec9aaeeb06
Author: Bruno P. Kinoshita <ki...@apache.org>
AuthorDate: Wed Jan 2 21:00:32 2019 +1300

    IMAGING-220: replace while by if in the JPEG decoder extend method
---
 .../imaging/formats/jpeg/decoder/JpegDecoder.java  |   2 +-
 .../formats/jpeg/decoder/JpegDecoderTest.java      |  47 +++++++++++++++++++++
 ...imeout-48eb4251935b4ca8b26d1859ea525c1b42ae0c78 | Bin 0 -> 932 bytes
 3 files changed, 48 insertions(+), 1 deletion(-)

diff --git 
a/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
 
b/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
index 3561fcb..2b21da2 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
@@ -400,7 +400,7 @@ public class JpegDecoder extends BinaryFileParser 
implements JpegUtils.Visitor {
     private int extend(int v, final int t) {
         // "EXTEND", section F.2.2.1, figure F.12, page 105 of T.81
         int vt = (1 << (t - 1));
-        while (v < vt) {
+        if (v < vt) {
             vt = (-1 << t) + 1;
             v += vt;
         }
diff --git 
a/src/test/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoderTest.java
 
b/src/test/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoderTest.java
new file mode 100644
index 0000000..20459a2
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoderTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.imaging.formats.jpeg.decoder;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.imaging.ImageReadException;
+import org.apache.commons.imaging.common.bytesource.ByteSourceFile;
+import org.junit.Test;
+
+/**
+ * Tests for the JpegDecoder.
+ */
+public class JpegDecoderTest {
+
+    /**
+     * Test that a bad file does not hang or take too long to be processed.
+     *
+     * @throws IOException
+     * @throws ImageReadException
+     */
+    @Test(expected = ImageReadException.class, timeout = 2000)
+    public void testDecodeBadFile() throws ImageReadException, IOException {
+        // From IMAGING-220
+        File inputFile = new File(
+                
JpegDecoderTest.class.getResource("/IMAGING-220/timeout-48eb4251935b4ca8b26d1859ea525c1b42ae0c78")
+                        .getFile());
+        ByteSourceFile byteSourceFile = new ByteSourceFile(inputFile);
+        new JpegDecoder().decode(byteSourceFile);
+    }
+}
diff --git 
a/src/test/resources/IMAGING-220/timeout-48eb4251935b4ca8b26d1859ea525c1b42ae0c78
 
b/src/test/resources/IMAGING-220/timeout-48eb4251935b4ca8b26d1859ea525c1b42ae0c78
new file mode 100644
index 0000000..3092589
Binary files /dev/null and 
b/src/test/resources/IMAGING-220/timeout-48eb4251935b4ca8b26d1859ea525c1b42ae0c78
 differ

Reply via email to