ICEpdf
  1. ICEpdf
  2. PDF-1336

Document.setByteArray(byte[], int, int, String) throws IOException for some PDF documents

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 6.3.2
    • Fix Version/s: None
    • Component/s: Core/Parsing
    • Labels:
      None
    • Environment:
      Windows 7 64 bit, Oracle JDK 8u60

      Description

      It seems like ICEpdf 6.3.2 introduced a regression, because with ICEpdf 6.2.2 everything works fine.

      If I try to load a PDF document via byte array using org.icepdf.core.pobjects.Document.setByteArray(byte[], int, int, String), it throws IOException with the following stack trace:

      ============================================
      java.io.IOException: java.lang.String cannot be cast to java.lang.Number
      at org.icepdf.core.pobjects.Document.setInputStream(Document.java:499)
      at org.icepdf.core.pobjects.Document.setByteArray(Document.java:365)
      at com.example.App.testPdf(App.java:13)
              ...
      ============================================


      And the following appears in standard error output stream:

      ============================================
      Dec 07, 2019 12:20:38 AM org.icepdf.core.pobjects.Catalog <clinit>
      INFO: ICEsoft ICEpdf Core 6.3.2
      Dec 07, 2019 12:20:38 AM org.icepdf.core.pobjects.Document setInputStream
      WARNING: Cross reference deferred loading failed, will fall back to linear reading.
      Dec 07, 2019 12:20:38 AM org.icepdf.core.pobjects.Document setInputStream
      SEVERE: Error loading PDF Document.
      java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
      at org.icepdf.core.util.Parser.getObject(Parser.java:150)
      at org.icepdf.core.pobjects.Document.loadDocumentViaLinearTraversal(Document.java:629)
      at org.icepdf.core.pobjects.Document.setInputStream(Document.java:478)
      at org.icepdf.core.pobjects.Document.setByteArray(Document.java:365)
      at com.example.App.testPdf(App.java:13)
              ...
      ============================================


      Here is the code snippet which I use to reproduce:

      ============================================
      package com.example;

      import org.icepdf.core.pobjects.Document;
      import java.nio.file.Files;
      import java.nio.file.Paths;

      public class App {
          public void testPdf(String pdfPath) throws Exception {
              byte[] bytes = Files.readAllBytes(Paths.get(pdfPath));
              Document document = new Document();
              document.setByteArray(bytes, 0, bytes.length, null);
              document.dispose();
          }
      }
      ============================================

      To test it, call this:
      new App().testPdf("/full/path/to/pdf/file.pdf");


      If needed, I can provide PDF documents, which cause this issue, via email channel.

        Activity

        Yauheni Sidarenka created issue -
        Hide
        Yauheni Sidarenka added a comment -

        I removed some empty lines in code snippet while I was creating this ticket. So,

        at com.example.App.testPdf(App.java:13)

        in stack traces should be read as

        at com.example.App.testPdf(App.java:11)
        
        Show
        Yauheni Sidarenka added a comment - I removed some empty lines in code snippet while I was creating this ticket. So, at com.example.App.testPdf(App.java:13) in stack traces should be read as at com.example.App.testPdf(App.java:11)
        Hide
        Yauheni Sidarenka added a comment -

        Also, I forgot to mention that I use single dependency on icepdf-core-6.3.2.jar to reproduce.

        Show
        Yauheni Sidarenka added a comment - Also, I forgot to mention that I use single dependency on icepdf-core-6.3.2.jar to reproduce.
        Hide
        Patrick Corless added a comment -

        Would it be possible for you to upload the file?

        Show
        Patrick Corless added a comment - Would it be possible for you to upload the file?
        Hide
        Yauheni Sidarenka added a comment -

        Unfortunately, no, it is not possible: I cannot make the file public because of copyright restrictions.

        Show
        Yauheni Sidarenka added a comment - Unfortunately, no, it is not possible: I cannot make the file public because of copyright restrictions.

          People

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

            Dates

            • Created:
              Updated: