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 2020/02/08 20:02:55 UTC
svn commit: r1873807 - in /pdfbox/branches/2.0/pdfbox/src:
main/java/org/apache/pdfbox/io/ScratchFileBuffer.java
test/java/org/apache/pdfbox/io/ScratchFileBufferTest.java
Author: tilman
Date: Sat Feb 8 20:02:55 2020
New Revision: 1873807
URL: http://svn.apache.org/viewvc?rev=1873807&view=rev
Log:
PDFBOX-4756: fix bug in seek() (wrong position and EOF), by Petr Slaby
Added:
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/io/ScratchFileBufferTest.java
- copied, changed from r1873806, pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/ScratchFileBufferTest.java
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java?rev=1873807&r1=1873806&r2=1873807&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java Sat Feb 8 20:02:55 2020
@@ -324,6 +324,10 @@ class ScratchFileBuffer implements Rando
}
int newPagePosition = (int) (seekToPosition / pageSize);
+ if (seekToPosition % pageSize == 0 && seekToPosition == size)
+ {
+ newPagePosition--; // PDFBOX-4756: Prevent seeking a non-yet-existent page...
+ }
currentPage = pageHandler.readPage(pageIndexes[newPagePosition]);
currentPagePositionInPageIndexes = newPagePosition;
Copied: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/io/ScratchFileBufferTest.java (from r1873806, pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/ScratchFileBufferTest.java)
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/io/ScratchFileBufferTest.java?p2=pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/io/ScratchFileBufferTest.java&p1=pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/ScratchFileBufferTest.java&r1=1873806&r2=1873807&rev=1873807&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/ScratchFileBufferTest.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/io/ScratchFileBufferTest.java Sat Feb 8 20:02:55 2020
@@ -41,22 +41,21 @@ public class ScratchFileBufferTest
@Test
public void testEOFBugInSeek() throws IOException
{
- try (ScratchFile scratchFile = new ScratchFile(MemoryUsageSetting.setupTempFileOnly()))
+ ScratchFile scratchFile = new ScratchFile(MemoryUsageSetting.setupTempFileOnly());
+ ScratchFileBuffer scratchFileBuffer = new ScratchFileBuffer(scratchFile);
+ byte[] bytes = new byte[PAGE_SIZE];
+ for (int i = 0; i < NUM_ITERATIONS; i++)
{
- ScratchFileBuffer scratchFileBuffer = new ScratchFileBuffer(scratchFile);
- byte[] bytes = new byte[PAGE_SIZE];
- for (int i = 0; i < NUM_ITERATIONS; i++)
- {
- long p0 = scratchFileBuffer.getPosition();
- scratchFileBuffer.write(bytes);
- long p1 = scratchFileBuffer.getPosition();
- Assert.assertEquals(PAGE_SIZE, p1 - p0);
- scratchFileBuffer.write(bytes);
- long p2 = scratchFileBuffer.getPosition();
- Assert.assertEquals(PAGE_SIZE, p2 - p1);
- scratchFileBuffer.seek(0);
- scratchFileBuffer.seek(i * 2 * PAGE_SIZE);
- }
+ long p0 = scratchFileBuffer.getPosition();
+ scratchFileBuffer.write(bytes);
+ long p1 = scratchFileBuffer.getPosition();
+ Assert.assertEquals(PAGE_SIZE, p1 - p0);
+ scratchFileBuffer.write(bytes);
+ long p2 = scratchFileBuffer.getPosition();
+ Assert.assertEquals(PAGE_SIZE, p2 - p1);
+ scratchFileBuffer.seek(0);
+ scratchFileBuffer.seek(i * 2 * PAGE_SIZE);
}
+ scratchFile.close();
}
}