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

Wasted work (or incorrect behavior) in PDCIDFontType2Font.readCIDToGIDMapping


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.2
    • Fix Version/s: 1.8.3, 2.0.0
    • Component/s: PDModel
    • Labels:
    • Environment:


      The problem appears in version 1.8.2 and in revision 1497941. I
      attached a two-line patch (patch.diff) that fixes it.

      In method "PDCIDFontType2Font.readCIDToGIDMapping", the loop:

      "for(int offset = 0;offset < numberOfInts;offset++)"

      keeps overriding "cid2gid[index]" with "getCodeFromArray(mapAsBytes,
      offset, 2)", where "index" does not change in the loop ("index" is
      always "0"). Therefore, only the last written value is visible out of
      the loop and all the previous writes and iterations are not necessary.
      The patch iterates from the end of the loop and breaks the first time
      when "cid2gid[index]" is set. The code can be further simplified, but
      I leave it like this to make the patch easy to follow.

      My patch preserves the original code behavior, but note that the
      original code (not the patch) may be incorrect to start with: maybe
      the code is not supposed to keep overriding "cid2gid[index]" (with
      "index" never changing in the loop, with value "0" all the time), but
      rather to also change "index". Maybe the code was supposed to be
      something like "cid2gid[index++]".


        1. patch.diff
          0.8 kB
          Adrian Nistor

          Issue Links



              • Assignee:
                lehmi Andreas Lehmkühler
                adriannistor Adrian Nistor
              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created: