pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1432658 - in /pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/io/RandomAccessBuffer.java test/java/org/apache/pdfbox/io/TestRandomAccessBuffer.java
Date Sun, 13 Jan 2013 16:59:36 GMT
Author: lehmi
Date: Sun Jan 13 16:59:36 2013
New Revision: 1432658

URL: http://svn.apache.org/viewvc?rev=1432658&view=rev
Log:
PDFBOX-1490: extend the buffer if the last byte was written to the last chunk

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/TestRandomAccessBuffer.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=1432658&r1=1432657&r2=1432658&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 Jan
13 16:59:36 2013
@@ -172,6 +172,7 @@ public class RandomAccessBuffer implemen
      */
     public void write(int b) throws IOException
     {
+        // end of buffer reached?
         if (currentBufferPointer >= BUFFER_SIZE) 
         {
             if (pointer + BUFFER_SIZE >= Integer.MAX_VALUE) 
@@ -186,6 +187,15 @@ public class RandomAccessBuffer implemen
         {
             this.size = pointer;
         }
+        // end of buffer reached now?
+        if (currentBufferPointer >= BUFFER_SIZE) 
+        {
+            if (pointer + BUFFER_SIZE >= Integer.MAX_VALUE) 
+            {
+                throw new IOException("RandomAccessBuffer overflow");
+            }
+            expandBuffer();
+        }
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/TestRandomAccessBuffer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/TestRandomAccessBuffer.java?rev=1432658&r1=1432657&r2=1432658&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/TestRandomAccessBuffer.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/TestRandomAccessBuffer.java Sun
Jan 13 16:59:36 2013
@@ -210,4 +210,16 @@ public class TestRandomAccessBuffer exte
         }
         assertEquals(25, result);
     }
+    
+    public void testPDFBOX1490() throws Exception
+    {
+        // create a buffer filled with 16383 * "0" 
+        byte[] byteArray = new byte[ BUFFER_SIZE-1];
+        RandomAccessBuffer buffer = new RandomAccessBuffer();
+        buffer.write(byteArray,0, byteArray.length);
+        // fill the first buffer until the end
+        buffer.write(0);
+        // seek the current == last position in the first buffer chunk
+        buffer.seek(buffer.getPosition());
+    }
 }



Mime
View raw message