pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1861274 - /pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessInputStream.java
Date Thu, 13 Jun 2019 16:38:07 GMT
Author: tilman
Date: Thu Jun 13 16:38:07 2019
New Revision: 1861274

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

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

Modified: pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessInputStream.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessInputStream.java?rev=1861274&r1=1861273&r2=1861274&view=diff
==============================================================================
--- pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessInputStream.java
(original)
+++ pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessInputStream.java
Thu Jun 13 16:38:07 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;
     }
 



Mime
View raw message