pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1551220 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Date Mon, 16 Dec 2013 15:02:47 GMT
Author: lehmi
Date: Mon Dec 16 15:02:46 2013
New Revision: 1551220

URL: http://svn.apache.org/r1551220
Log:
PDFBOX-1769: avoid false error messages when checking xref tables, calculate the correct number
of bytes to be unread

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1551220&r1=1551219&r2=1551220&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Mon Dec 16 15:02:46 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();



Mime
View raw message