commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1748015 - in /commons/proper/imaging/trunk/src: changes/changes.xml main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
Date Sun, 12 Jun 2016 14:47:11 GMT
Author: britter
Date: Sun Jun 12 14:47:11 2016
New Revision: 1748015

URL: http://svn.apache.org/viewvc?rev=1748015&view=rev
Log:
IMAGING-178: PnmImageParser does not check the validity of input PAM header. Thanks to emopers.
This also fixes #20 from github.

Modified:
    commons/proper/imaging/trunk/src/changes/changes.xml
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
    commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java

Modified: commons/proper/imaging/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/changes/changes.xml?rev=1748015&r1=1748014&r2=1748015&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/changes/changes.xml (original)
+++ commons/proper/imaging/trunk/src/changes/changes.xml Sun Jun 12 14:47:11 2016
@@ -46,6 +46,9 @@ The <action> type attribute can be add,u
   <body>
 
     <release version="1.0" date="TBA" description="First major release">
+      <action issue="IMAGING-178" dev="britter" type="fix" due-to="emopers">
+        PnmImageParser does not check the validity of input PAM header.
+      </action>
       <action issue="IMAGING-184" dev="ggregory" type="update">
         Update platform from Java 5 to 7
       </action>

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java?rev=1748015&r1=1748014&r2=1748015&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
Sun Jun 12 14:47:11 2016
@@ -157,18 +157,28 @@ public class PnmImageParser extends Imag
                 final String type = tokenizer.nextToken();
                 if ("WIDTH".equals(type)) {
                     seenWidth = true;
+                    if(!tokenizer.hasMoreTokens())
+                        throw new ImageReadException("PAM header has no WIDTH value");
                     width = Integer.parseInt(tokenizer.nextToken());
                 } else if ("HEIGHT".equals(type)) {
                     seenHeight = true;
+                    if(!tokenizer.hasMoreTokens())
+                        throw new ImageReadException("PAM header has no HEIGHT value");
                     height = Integer.parseInt(tokenizer.nextToken());
                 } else if ("DEPTH".equals(type)) {
                     seenDepth = true;
+                    if(!tokenizer.hasMoreTokens())
+                        throw new ImageReadException("PAM header has no DEPTH value");
                     depth = Integer.parseInt(tokenizer.nextToken());
                 } else if ("MAXVAL".equals(type)) {
                     seenMaxVal = true;
+                    if(!tokenizer.hasMoreTokens())
+                        throw new ImageReadException("PAM header has no MAXVAL value");
                     maxVal = Integer.parseInt(tokenizer.nextToken());
                 } else if ("TUPLTYPE".equals(type)) {
                     seenTupleType = true;
+                    if(!tokenizer.hasMoreTokens())
+                        throw new ImageReadException("PAM header has no TUPLTYPE value");
                     tupleType.append(tokenizer.nextToken());
                 } else if ("ENDHDR".equals(type)) {
                     break;

Modified: commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java?rev=1748015&r1=1748014&r2=1748015&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
(original)
+++ commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
Sun Jun 12 14:47:11 2016
@@ -46,4 +46,12 @@ public class PnmImageParserTest {
     PnmImageParser underTest = new PnmImageParser();
     underTest.getImageInfo(bytes, params);
   }
+
+  @Test(expected = ImageReadException.class)
+  public void testGetImageInfo_missingWidthValue() throws ImageReadException, IOException
{
+    byte[] bytes = "P7\nWIDTH \n".getBytes(US_ASCII);
+    Map<String, Object> params = Collections.emptyMap();
+    PnmImageParser underTest = new PnmImageParser();
+    underTest.getImageInfo(bytes, params);
+  }
 }



Mime
View raw message