Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-979

errors in %%EOF handling (fix included)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.0
    • Fix Version/s: 1.6.0
    • Component/s: Parsing
    • Labels:
      None

      Description

      The '%%EOF' handling in PDFParser has several errors. The current implementation (start from line 467):

      String eof = "";
      if(!pdfSource.isEOF())
      readLine(); // if there's more data to read, get the EOF flag

      // verify that EOF exists
      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")); }

      The problems:

      • eof variable gets no value
      • comparison if("%%EOF".equals(eof)) must be negated
      • unreading must first add a newline or space byte because we read with readline() (like in bug PDFBOX-978)

      Corrected version:
      String eof = "";
      if(!pdfSource.isEOF())
      eof = readLine(); // if there's more data to read, get the EOF flag

      // verify that EOF exists
      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( SPACE_BYTE ); // we read a whole line; add space as newline replacement pdfSource.unread(eof.getBytes("ISO-8859-1")); }

      }

        Attachments

          Activity

            People

            • Assignee:
              adamnichols Adam Nichols
              Reporter:
              tboehme Timo Boehme
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: