You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2018/10/21 10:58:29 UTC

svn commit: r1844477 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java

Author: lehmi
Date: Sun Oct 21 10:58:29 2018
New Revision: 1844477

URL: http://svn.apache.org/viewvc?rev=1844477&view=rev
Log:
PDFBOX-4351: handle premature end of stream to avoid IOOBE

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java?rev=1844477&r1=1844476&r2=1844477&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java Sun Oct 21 10:58:29 2018
@@ -52,16 +52,30 @@ final class InputStreamSource implements
     public int read(byte[] b) throws IOException
     {
         int n = input.read(b);
-        position += n;
-        return n;
+        if (n > 0)
+        {
+            position += n;
+            return n;
+        }
+        else
+        {
+            return -1;
+        }
     }
 
     @Override
     public int read(byte[] b, int offset, int length) throws IOException
     {
         int n = input.read(b, offset, length);
-        position += n;
-        return n;
+        if (n > 0)
+        {
+            position += n;
+            return n;
+        }
+        else
+        {
+            return -1;
+        }
     }
 
     @Override
@@ -111,9 +125,16 @@ final class InputStreamSource implements
         while (len > 0)
         {
             int n = this.read(bytes, off, len);
-            off += n;
-            len -= n;
-            position += n;
+            if (n > 0)
+            {
+                off += n;
+                len -= n;
+                position += n;
+            }
+            else
+            {
+                break;
+            }
         }
         return bytes;
     }