You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2015/07/10 19:23:54 UTC
svn commit: r1690292 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java
Author: lehmi
Date: Fri Jul 10 17:23:53 2015
New Revision: 1690292
URL: http://svn.apache.org/r1690292
Log:
PDFBOX-2869: avoid corruption as proposed by Jesse Long
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java?rev=1690292&r1=1690291&r2=1690292&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java Fri Jul 10 17:23:53 2015
@@ -432,21 +432,21 @@ class ScratchFileBuffer implements Rando
return -1;
}
- seekToCurrentPositionInFile();
-
- if (positionInPage == PAGE_SIZE - 8)
- {
- currentPage = raFile.readLong();
- positionInPage = 8;
- seekToCurrentPositionInFile();
- }
-
len = (int) Math.min(len, length - positionInBuffer);
+ seekToCurrentPositionInFile();
+
int totalBytesRead = 0;
while (len > 0)
{
+ if (positionInPage == PAGE_SIZE - 8)
+ {
+ currentPage = raFile.readLong();
+ positionInPage = 8;
+ seekToCurrentPositionInFile();
+ }
+
int availableInThisPage = (PAGE_SIZE - 8) - positionInPage;
int rdbytes = raFile.read(b, off, Math.min(len, availableInThisPage));
@@ -456,17 +456,7 @@ class ScratchFileBuffer implements Rando
throw new IOException("EOF reached before end of scratch file stream");
}
- if (rdbytes == availableInThisPage)
- {
- currentPage = raFile.readLong();
- positionInPage = 8;
- seekToCurrentPositionInFile();
- }
- else
- {
- positionInPage += rdbytes;
- }
-
+ positionInPage += rdbytes;
totalBytesRead += rdbytes;
positionInBuffer += rdbytes;
off += rdbytes;