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

IndexOutOfBoundsException when setting DefaultFontProvider in FontMapper

    XMLWordPrintableJSON

    Details

      Description

      When parsing certain pdf's, I'm encountering an IndexOutOfBoundsException in WindowsFontDirFinder.java on line 106:

      psFontsDir = new File(windir.substring(0, 2) + File.separator + "PSFONTS");
      

      WindowsFontDirFinder is used by the statement on line 128 in FontMapperImpl.java in my case:

      private static final FontProvider INSTANCE = new FileSystemFontProvider(fontCache);
      

      The cause of the error is that the value of windir is "" (empty string), at least during debugging in Windows. However, I should mention that parsing of the same document also fails on ubuntu. While I don't know the exact mechanism of the failure on ubuntu, I assume it is related.

      The code checks whether windir is null before doing the substring operation, but not whether the length is in fact >2. I'm not sure why windir ends up being "" here, as the windir env var is C:\WINDOWS.

       

      A working fix for me was to change the windir null check on line 94 to:

      if (windir != null && !windir.equals(""))
      

        Attachments

          Activity

            People

            • Assignee:
              tilman Tilman Hausherr
              Reporter:
              joanil Joakim Nilsson
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified