You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ad...@apache.org on 2011/03/21 17:23:29 UTC

svn commit: r1083857 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java

Author: adam
Date: Mon Mar 21 16:23:28 2011
New Revision: 1083857

URL: http://svn.apache.org/viewvc?rev=1083857&view=rev
Log:
PDFBOX-979: errors in %%EOF handling

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java?rev=1083857&r1=1083856&r2=1083857&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java Mon Mar 21 16:23:28 2011
@@ -468,14 +468,20 @@ public class PDFParser extends BaseParse
                 if(!pdfSource.isEOF())
                     eof = readLine(); // if there's more data to read, get the EOF flag
                 
-                // verify that EOF exists
+                // verify that EOF exists (see PDFBOX-979 for documentation on special cases)
                 if(!"%%EOF".equals(eof)) {
-                    // PDF does not conform to spec, we should warn someone
-                    log.warn("expected='%%EOF' actual='" + eof + "'");
-                    // if we're not at the end of a file, just put it back and move on
-                    if(!pdfSource.isEOF()) {
-                        pdfSource.unread(eof.getBytes("ISO-8859-1"));
-                        pdfSource.unread( SPACE_BYTE ); // we read a whole line; add space as newline replacement 
+                    if(eof.startsWith("%%EOF")) {
+                        // content after marker -> unread with first space byte for read newline
+                        pdfSource.unread(SPACE_BYTE); // we read a whole line; add space as newline replacement 
+                        pdfSource.unread(eof.substring(5).getBytes("ISO-8859-1"));
+                    } else {
+                        // PDF does not conform to spec, we should warn someone 
+                        log.warn("expected='%%EOF' actual='" + eof + "'"); 
+                        // if we're not at the end of a file, just put it back and move on 
+                        if(!pdfSource.isEOF()) { 
+                            pdfSource.unread( SPACE_BYTE ); // we read a whole line; add space as newline replacement 
+                            pdfSource.unread(eof.getBytes("ISO-8859-1")); 
+                        }
                     }
                 }
                 isEndOfFile = true;