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

StringIndexOutOfBoundsException in AppearanceGeneratorHelper

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.0.32, 3.0.2 PDFBox
    • 2.0.33, 3.0.3 PDFBox, 4.0.0
    • AcroForm
    • None

    Description

      The bug fix for PDFBOX-5784 created another issue.

      In AppearanceGeneratorHelper line 676 is assumed, that fields have non-empty values:

       

      font.getStringWidth(value.substring(0, 1))

       

      resulting in this exceptions for empty fields, for example when refreshAppearances is called:

       

      java.lang.StringIndexOutOfBoundsException: begin 0, end 1, length 0
      
          at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4602)
          at java.base/java.lang.String.substring(String.java:2705)
          at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:676)
          at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:569)
          at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:441)
          at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:248)
          at org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
          at org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm.refreshAppearances(PDAcroForm.java:361)

       

       

      Attachments

        Issue Links

          Activity

            People

              tilman Tilman Hausherr
              _ncc_ Nicola Costantini
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: