[GitHub] kinow closed pull request #40: IMAGING-220: replace while by if in the JPEG decoder extend method

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] kinow closed pull request #40: IMAGING-220: replace while by if in the JPEG decoder extend method

GitBox
kinow closed pull request #40: IMAGING-220: replace while by if in the JPEG decoder extend method
URL: https://github.com/apache/commons-imaging/pull/40
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 3561fcbc..2b21da2c 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 @@ private static int fastRound(final float x) {
     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 00000000..20459a25
--- /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 00000000..30925893
Binary files /dev/null and b/src/test/resources/IMAGING-220/timeout-48eb4251935b4ca8b26d1859ea525c1b42ae0c78 differ


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]