pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1685399 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java
Date Sun, 14 Jun 2015 12:54:46 GMT
Author: lehmi
Date: Sun Jun 14 12:54:45 2015
New Revision: 1685399

URL: http://svn.apache.org/r1685399
Log:
PDFBOX-2301, PDFBOX-2829: handle positions beyond EOF within seek

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java?rev=1685399&r1=1685398&r2=1685399&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java Sun Jun
14 12:54:45 2015
@@ -168,11 +168,26 @@ public class RandomAccessBuffer implemen
     public void seek(long position) throws IOException
     {
         checkClosed();
+        if (position < 0)
+        {
+            throw new IOException("Invalid position "+position);
+        }
         pointer = position;
-        // calculate the chunk list index
-        bufferListIndex = (int)(position / chunkSize);
-        currentBufferPointer = (int)(position % chunkSize);
-        currentBuffer = bufferList.get(bufferListIndex);
+        if (pointer <= size)
+        {
+            // calculate the chunk list index
+            bufferListIndex = (int)(position / chunkSize);
+            currentBufferPointer = (int)(position % chunkSize);
+            currentBuffer = bufferList.get(bufferListIndex);
+        }
+        else
+        {
+            // it is allowed to jump beyond the end of the file
+            // jump to the end of the buffer
+            bufferListIndex = bufferListMaxIndex;
+            currentBuffer = bufferList.get(bufferListIndex);
+            currentBufferPointer = (int)(size - ((bufferListMaxIndex-1)*chunkSize));
+        }
     }
 
     /**



Mime
View raw message