Lawrence Kesteloot created PDFBOX-3554:
------------------------------------------

             Summary: Crash in kerning calculations
                 Key: PDFBOX-3554
                 URL: https://issues.apache.org/jira/browse/PDFBOX-3554
             Project: PDFBox
          Issue Type: Bug
          Components: FontBox
    Affects Versions: 2.0.0
            Reporter: Lawrence Kesteloot


A bug in the usage of the result of a binary search causes a crash in the 
calculation of kerning information. Here's the patch:

{code}
--- a/fontbox/src/main/java/org/apache/fontbox/ttf/KerningSubtable.java
+++ b/fontbox/src/main/java/org/apache/fontbox/ttf/KerningSubtable.java
@@ -292,7 +292,7 @@ public class KerningSubtable
             index = Arrays.binarySearch(pairs, searchRange, pairs.length, key, 
this);
             if (index >= 0)
             {
-                return pairs[searchRange + index][2];
+                return pairs[index][2];
             }
             return 0;
         }
{code}

Explanation: The searchRange parameter is passed to binarySearch(), but the 
result of binarySearch() is relative to the start of the array, not the 
passed-in start. So no need to add searchRange to the result. Adding causes the 
indexing to go off the end of the array.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to