pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1862171 - /pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java
Date Wed, 26 Jun 2019 17:30:35 GMT
Author: tilman
Date: Wed Jun 26 17:30:34 2019
New Revision: 1862171

URL: http://svn.apache.org/viewvc?rev=1862171&view=rev
Log:
PDFBOX-4580: check order of FeatureRecord array in the hope to detect corrupt table

Modified:
    pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java

Modified: pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java?rev=1862171&r1=1862170&r2=1862171&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java
(original)
+++ pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java
Wed Jun 26 17:30:34 2019
@@ -167,12 +167,22 @@ public class GlyphSubstitutionTable exte
         int featureCount = data.readUnsignedShort();
         FeatureRecord[] featureRecords = new FeatureRecord[featureCount];
         int[] featureOffsets = new int[featureCount];
+        String prevFeatureTag = "";
         for (int i = 0; i < featureCount; i++)
         {
             FeatureRecord featureRecord = new FeatureRecord();
             featureRecord.featureTag = data.readString(4);
+            if (i > 0 && featureRecord.featureTag.compareTo(prevFeatureTag) <
0)
+            {
+                // catch corrupt file
+                // https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#flTbl
+                LOG.error("FeatureRecord array not alphabetically sorted by FeatureTag: "
+
+                           featureRecord.featureTag + " < " + prevFeatureTag);
+                return new FeatureRecord[0];
+            }
             featureOffsets[i] = data.readUnsignedShort();
             featureRecords[i] = featureRecord;
+            prevFeatureTag = featureRecord.featureTag;
         }
         for (int i = 0; i < featureCount; i++)
         {



Mime
View raw message