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 2013/12/17 12:19:14 UTC
svn commit: r1551514 - in /pdfbox/branches/1.8: ./
pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Author: lehmi
Date: Tue Dec 17 11:19:14 2013
New Revision: 1551514
URL: http://svn.apache.org/r1551514
Log:
PDFBOX-1769: avoid false error messages when checking xref tables, calculate the correct number of bytes to be unread
Modified:
pdfbox/branches/1.8/ (props changed)
pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Propchange: pdfbox/branches/1.8/
------------------------------------------------------------------------------
Merged /pdfbox/trunk:r1551220
Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1551514&r1=1551513&r2=1551514&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java Tue Dec 17 11:19:14 2013
@@ -1521,9 +1521,9 @@ public class NonSequentialPDFParser exte
boolean useReadUntilEnd = false;
// ---- get output stream to copy data to
- out = stream.createFilteredStream(streamLengthObj);
if (validateStreamLength(streamLengthObj.longValue()))
{
+ out = stream.createFilteredStream(streamLengthObj);
long remainBytes = streamLengthObj.longValue();
int bytesRead = 0;
while (remainBytes > 0)
@@ -1533,6 +1533,7 @@ public class NonSequentialPDFParser exte
if (readBytes <= 0)
{
useReadUntilEnd = true;
+ out.close();
pdfSource.unread(bytesRead);
break;
}
@@ -1604,8 +1605,8 @@ public class NonSequentialPDFParser exte
// beginning of buffer
while ((bufSize = pdfSource.read(streamCopyBuf, charMatchCount, streamCopyBufLen - charMatchCount)) > 0)
{
- bufSize += charMatchCount;
-
+ // number of already matching chars
+ int startingMatchCount = charMatchCount;
int bIdx = charMatchCount;
int quickTestIdx;
@@ -1684,9 +1685,9 @@ public class NonSequentialPDFParser exte
}
if (charMatchCount == keyw.length)
{
- // keyword matched; unread matched keyword (endstream/endobj)
- // and following buffered content
- pdfSource.unread(streamCopyBuf, contentBytes, bufSize - contentBytes);
+ // keyword matched;
+ // unread matched keyword (endstream/endobj) and following buffered content
+ pdfSource.unread(streamCopyBuf, contentBytes, bufSize - contentBytes - keyw.length + startingMatchCount);
break;
}
@@ -1850,7 +1851,9 @@ public class NonSequentialPDFParser exte
for (COSObjectKey objectKey : xrefOffset.keySet())
{
Long objectOffset = xrefOffset.get(objectKey);
- if (objectOffset != null)
+ // a negative offset number represents a object number itself
+ // see type 2 entry in xref stream
+ if (objectOffset != null && objectOffset > 0)
{
long objectNr = objectKey.getNumber();
long objectGen = objectKey.getGeneration();