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

PDGraphicsState class receives null page argument leading to nullpointerexception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.7.1
    • 1.8.1
    • PDModel, Utilities
    • None
    • all (os-x, ubuntu linux, win-32, win64)

    Description

      workaround changes needed for PDGraphicsState constructor as reproduced below:

      attached pdf file can be used to reproduce the exception

      public PDGraphicsState(PDRectangle page) {

      /*

      • TB - changes made here are a workaround which creates a default
      • GeneralPath assigned to currentClippingPath if the constructor
      • argument page is null. Probably a better remedy would be to ensure
      • that the page argument is not null or use a dedicated constructor if
      • page is null
        */

      if (page != null) {

      Dimension dimension = page.createDimension();

      Rectangle rectangle = new Rectangle(dimension);

      currentClippingPath = new GeneralPath(rectangle);

      currentClippingPath = new GeneralPath(new Rectangle(page.createDimension()));
      if (page.getLowerLeftX() != 0 || page.getLowerLeftY() != 0)

      { // Compensate for offset this.currentTransformationMatrix = this.currentTransformationMatrix.multiply(Matrix.getTranslatingInstance(-page.getLowerLeftX(), -page.getLowerLeftY())); }

      } else

      { currentClippingPath = new GeneralPath(); }

      }

      Also, as a side effect of above workaround, made following change within PDFStreamEngine.processEncodedText:

      /*

      • TB - needed to make change here, as we encounter here a knock on
      • effect of allowing null page arguments through in PDGraphicsState
      • constructor which creates a default GeneralPath assigned to
      • currentClippingPath. That workaround causes findMediaBox to return
      • null, so in that case we assign default values to pageHeight and
      • pageWidth here. Everything else seems to work as far as text
      • extraction is concerned.
        */
        if (page.findMediaBox() != null) { pageHeight = page.findMediaBox().getHeight(); pageWidth = page.findMediaBox().getWidth(); }

        else

        { pageHeight = 0; pageWidth = 0; }

      Attachments

        1. The right to take risks.pdf
          90 kB
          Tim Barrett

        Activity

          People

            lehmi Andreas Lehmkühler
            comcortim Tim Barrett
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: