ICEpdf
  1. ICEpdf
  2. PDF-1010

java.lang.NullPointerException thrown when try to open some PDFs

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 6.1.2
    • Fix Version/s: 6.1.3
    • Component/s: Core/Parsing
    • Labels:
      None
    • Environment:
      All
    • Workaround Exists:
      Yes
    • Workaround Description:
      Hide
      If I change convertToString in CMap class in the way below the PDF is showed. But I think that this is a workaround rather than a fix of the problem.

      private char[] convertToString(CharSequence s) {
              if (s == null && s.length() % 2 != 0) {
                  throw new IllegalArgumentException();
              }
              int len = s.length();
              if (len == 1) {
                  return new char[]{s.charAt(0)};
              }
              char[] dest = new char[len / 2];
              for (int i = 0, j = 0; i < len; i += 2, j++) {
                  dest[j] = (char) ((s.charAt(i) << 8) | s.charAt(i + 1));
              }
              return dest;
          }
      Show
      If I change convertToString in CMap class in the way below the PDF is showed. But I think that this is a workaround rather than a fix of the problem. private char[] convertToString(CharSequence s) {         if (s == null && s.length() % 2 != 0) {             throw new IllegalArgumentException();         }         int len = s.length();         if (len == 1) {             return new char[]{s.charAt(0)};         }         char[] dest = new char[len / 2];         for (int i = 0, j = 0; i < len; i += 2, j++) {             dest[j] = (char) ((s.charAt(i) << 8) | s.charAt(i + 1));         }         return dest;     }

      Description

      When rendering the provided PDF file the following exceptions are thrown and the content of the PDF is rendered blank:

      ICEsoft ICEpdf Viewer x.x.x x
      Copyright ICEsoft Technologies, Inc.

      lug 15, 2016 10:03:01 AM org.icepdf.core.pobjects.Catalog <clinit>
      INFORMAZIONI: ICEsoft ICEpdf Core x.x.x x
      lug 15, 2016 10:03:01 AM org.icepdf.core.pobjects.Resources getFont
      AVVERTENZA: Error initializing font, falling back to font substitution.
      lug 15, 2016 10:03:01 AM org.icepdf.core.util.content.AbstractContentParser consume_Tf
      AVVERTENZA: Warning could not find font by named resource C2_0
      lug 15, 2016 10:03:01 AM org.icepdf.core.pobjects.Resources getFont
      AVVERTENZA: Error initializing font, falling back to font substitution.
      lug 15, 2016 10:03:01 AM org.icepdf.core.util.content.AbstractContentParser consume_Tf
      AVVERTENZA: Warning could not find font by named resource C2_0
      lug 15, 2016 10:03:01 AM org.icepdf.core.util.content.NContentParser parse
      AVVERTENZA: Error parsing content stream.
      java.lang.NullPointerException
      at org.icepdf.core.util.content.AbstractContentParser.consume_Tf(AbstractContentParser.java:833)
      at org.icepdf.core.util.content.NContentParser.parse(NContentParser.java:174)
      at org.icepdf.core.pobjects.Page.init(Page.java:404)
      at org.icepdf.ri.common.views.PageViewComponentImpl$PageInitializer.run(PageViewComponentImpl.java:1180)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)

      The problem is that the convertToString method of CMap.java class receives a CharSequence s of length 1.

      P.S. Incidentally I noted that the same method contains a bug: if (s == null && s.length() % 2 != 0) I think should instead be if (s == null || s.length() % 2 != 0). But I don't think that is the problem.
      1. Atto2.pdf
        894 kB
        Giorgio Fiderio
      1. IcePDFTest.png
        414 kB

        Activity

        Giorgio Fiderio created issue -
        Hide
        Giorgio Fiderio added a comment -

        The file affected by the problem

        Show
        Giorgio Fiderio added a comment - The file affected by the problem
        Giorgio Fiderio made changes -
        Field Original Value New Value
        Attachment Atto2.pdf [ 22253 ]
        Patrick Corless made changes -
        Fix Version/s 6.1.3 [ 13086 ]
        Hide
        Patrick Corless added a comment -

        I wasn't able to reproduce this using the 6.1.2 code. The font resource /C2_0 loaded correctly. Could you give me a little more info on your environment and the source your building with. You logging seems to indicate you might be using a trunk build?

        Show
        Patrick Corless added a comment - I wasn't able to reproduce this using the 6.1.2 code. The font resource /C2_0 loaded correctly. Could you give me a little more info on your environment and the source your building with. You logging seems to indicate you might be using a trunk build?
        Hide
        Giorgio Fiderio added a comment -

        Hi Patrick,
        To produce the problem I downloaded ICEpdf-6.1.2-src.zip (the last open source release 6.1.2) from http://www.icesoft.org/java/downloads/icepdf-downloads.jsf, I run org.icepdf.ri.viewer.Main and opened the attached PDF Atto2.pdf and I obtained a blank page. I debugged and found that the convertToString method of org.icepdf.core.pobjects.fonts.ofont.CMap.java class receives a CharSequence s of length 1 so throws a "java.lang.StringIndexOutOfBoundsException: String index out of range: 1" catched by getFont method in org.icepdf.core.pobjects.Resources.java that logs "Error initializing font, falling back to font substitution. FONT= null

        {ToUnicode=27 0 R, Type=Font, BaseFont=Calibri, Encoding=Identity-H, DescendantFonts=[39 0 R], Subtype=Type0}

        " with FINER log level.

        Thanks for your help.

        Show
        Giorgio Fiderio added a comment - Hi Patrick, To produce the problem I downloaded ICEpdf-6.1.2-src.zip (the last open source release 6.1.2) from http://www.icesoft.org/java/downloads/icepdf-downloads.jsf , I run org.icepdf.ri.viewer.Main and opened the attached PDF Atto2.pdf and I obtained a blank page. I debugged and found that the convertToString method of org.icepdf.core.pobjects.fonts.ofont.CMap.java class receives a CharSequence s of length 1 so throws a "java.lang.StringIndexOutOfBoundsException: String index out of range: 1" catched by getFont method in org.icepdf.core.pobjects.Resources.java that logs "Error initializing font, falling back to font substitution. FONT= null {ToUnicode=27 0 R, Type=Font, BaseFont=Calibri, Encoding=Identity-H, DescendantFonts=[39 0 R], Subtype=Type0} " with FINER log level. Thanks for your help.
        Hide
        Patrick Corless added a comment -

        Unfortunately I can't reproduce this on my windows system, perhaps some underlying encoding issue. But I don't see anything wrong with adding a little more code protection.

        Show
        Patrick Corless added a comment - Unfortunately I can't reproduce this on my windows system, perhaps some underlying encoding issue. But I don't see anything wrong with adding a little more code protection.
        Hide
        Patrick Corless added a comment -

        Marking as fixed.

        Show
        Patrick Corless added a comment - Marking as fixed.
        Patrick Corless made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Repository Revision Date User Message
        ICEsoft Public SVN Repository #49156 Fri Sep 02 09:47:29 MDT 2016 patrick.corless PDF-1010 addition of code protection to avoid index out of bounds exception on some systems if char sequence length is 1.
        Files Changed
        Commit graph MODIFY /icepdf/branches/icepdf-6.1.0/icepdf/core/src/org/icepdf/core/pobjects/fonts/ofont/CMap.java
        Giorgio Fiderio made changes -
        Attachment IcePDFTest.png [ 22275 ]
        Hide
        Giorgio Fiderio added a comment -

        Hi Patrick,
        I'm sorry but I just tried to open the attached pdf with Open Source ICEsoft ICEpdf Viewer 6.1.2 on Windows system and the result is the blank PDF and the java stack trace in the attached PNG. Truly I don't understand why you can't reproduce the problem.

        Show
        Giorgio Fiderio added a comment - Hi Patrick, I'm sorry but I just tried to open the attached pdf with Open Source ICEsoft ICEpdf Viewer 6.1.2 on Windows system and the result is the blank PDF and the java stack trace in the attached PNG. Truly I don't understand why you can't reproduce the problem.
        Repository Revision Date User Message
        ICEsoft Public SVN Repository #49490 Tue Nov 08 10:35:12 MST 2016 patrick.corless PDF-1010 addition of code protection to avoid index out of bounds exception on some systems if char sequence length is 1.
        Files Changed
        Commit graph MODIFY /icepdf/trunk/icepdf/core/src/org/icepdf/core/pobjects/fonts/ofont/CMap.java
        Patrick Corless made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Patrick Corless
            Reporter:
            Giorgio Fiderio
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: