You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2019/06/13 16:38:12 UTC

svn commit: r1861275 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessInputStream.java

Author: tilman
Date: Thu Jun 13 16:38:12 2019
New Revision: 1861275

URL: http://svn.apache.org/viewvc?rev=1861275&view=rev
Log:
PDFBOX-4559: if read failed don't alter position and log error

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessInputStream.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessInputStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessInputStream.java?rev=1861275&r1=1861274&r2=1861275&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessInputStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessInputStream.java Thu Jun 13 16:38:12 2019
@@ -19,6 +19,9 @@ package org.apache.pdfbox.io;
 import java.io.InputStream;
 import java.io.IOException;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * An InputStream which reads from a RandomAccessRead.
  * 
@@ -27,6 +30,8 @@ import java.io.IOException;
  */
 public class RandomAccessInputStream extends InputStream
 {
+    private static final Log LOG = LogFactory.getLog(RandomAccessInputStream.class);
+
     private final RandomAccessRead input;
     private long position;
 
@@ -68,7 +73,17 @@ public class RandomAccessInputStream ext
             return -1;
         }
         int b = input.read();
-        position += 1;
+        if (b != -1)
+        {
+            position += 1;
+        }
+        else
+        {
+            // should never happen due to prior isEOF() check
+            // unless there is an unsynchronized concurrent access
+            LOG.error("read() returns -1, assumed position: " +
+                       position + ", actual position: " + input.getPosition());
+        }
         return b;
     }
 
@@ -81,7 +96,17 @@ public class RandomAccessInputStream ext
             return -1;
         }
         int n = input.read(b, off, len);
-        position += n;
+        if (n != -1)
+        {
+            position += n;
+        }
+        else
+        {
+            // should never happen due to prior isEOF() check
+            // unless there is an unsynchronized concurrent access
+            LOG.error("read() returns -1, assumed position: " +
+                       position + ", actual position: " + input.getPosition());
+        }
         return n;
     }