Uploaded image for project: 'FOP'
  1. FOP
  2. FOP-2920

[PATCH] Surrogate pair edge-case causes java.lang.ArrayIndexOutOfBoundsException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.5
    • 2.9
    • renderer/pdf
    • None
    • macOS Mojave
      java version "1.8.0_192-ea"
      Java(TM) SE Runtime Environment (build 1.8.0_192-ea-b04)
      Java HotSpot(TM) 64-Bit Server VM (build 25.192-b04, mixed mode)

    Description

      fop-core/src/main/java/org/apache/fop/pdf/PDFToUnicodeCMap.java writeBFCharEntries runs through the codepoint entries in sections of 100 at a time. It looks like there's an edge case here where the last entry in the section is a surrogate pair.

       

      Here's my steps to reproduce from the latest trunk:

      java -cp fop/target/fop-2.5.0-SNAPSHOT.jar:fop/lib/commons-logging-1.0.4.jar:fop/lib/commons-io-1.3.1.jar:fop/lib/xmlgraphics-commons-svn-trunk.jar org.apache.fop.fonts.apps.TTFReader TwitterColorEmoji-SVGinOT.ttf twe.xml

      java -cp fop/target/fop-2.5.0-SNAPSHOT.jar:fop/lib/commons-logging-1.0.4.jar:fop/lib/commons-io-1.3.1.jar:fop/lib/xmlgraphics-commons-svn-trunk.jar:fop/lib/batik-all-1.11.0-SNAPSHOT.jar org.apache.fop.cli.Main -c twe_userconfig.xml -xsl twe_template.fo -xml fail.xml -pdf fail.pdf

       

      Here's the temporary way I resolved it for my own build:

       

      index ee773dcec..37c21803e 100644
      — a/fop-core/src/main/java/org/apache/fop/pdf/PDFToUnicodeCMap.java
      +++ b/fop-core/src/main/java/org/apache/fop/pdf/PDFToUnicodeCMap.java
      @@ -128,6 +128,18 @@ public class PDFToUnicodeCMap extends PDFCMap {
      while (partOfRange(charArray, charIndex))

      { charIndex++; }

      /*

      • If this entry is going to overflow the entriesThisSection
      • array, then don't use it. This happens if there are
      • non-pair entries in the table mixed with pair entries.
        */
        if (Character.codePointAt(charArray, charIndex) > 0xFFFF
        && i+1 >= entriesThisSection) { entriesThisSection--; break; }

      writer.write("<" + padCharIndex(charIndex) + "> ");

      if (Character.codePointAt(charArray, charIndex) > 0xFFFF) {

      Attachments

        1. twe_template.fo
          0.8 kB
          Kelly H Wilkerson
        2. fail.xml
          0.3 kB
          Kelly H Wilkerson
        3. twe_userconfig.xml
          27 kB
          Kelly H Wilkerson
        4. TwitterColorEmoji-SVGinOT.ttf
          9.76 MB
          Kelly H Wilkerson
        5. diff.txt
          1 kB
          Kelly H Wilkerson
        6. 2920.patch
          1 kB
          Kelly H Wilkerson
        7. s6.patch
          45 kB
          Dave Roxburgh
        8. fop.xconf
          0.5 kB
          Simon Steiner

        Activity

          People

            ssteiner Simon Steiner
            kwilkerson Kelly H Wilkerson
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: