Skip to content

Commit d8b3723

Browse files
Make OpenTypeFontTableReader tolerant to NULL offset in LookupList table
DEVSIX-1813
1 parent a05a7c5 commit d8b3723

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

io/src/main/java/com/itextpdf/io/font/otf/OpenTypeFontTableReader.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@
5454
import java.util.Set;
5555

5656
/**
57-
*
57+
*
5858
* @author <a href="mailto:[email protected]">Palash Ray</a>
5959
*/
6060
public abstract class OpenTypeFontTableReader implements Serializable {
6161

6262
private static final long serialVersionUID = 4826484598227913292L;
6363
protected final RandomAccessFileOrArray rf;
6464
protected final int tableLocation;
65-
65+
6666
protected List<OpenTableLookup> lookupList;
6767
protected OpenTypeScript scriptsType;
6868
protected OpenTypeFeature featuresType;
@@ -79,11 +79,11 @@ protected OpenTypeFontTableReader(RandomAccessFileOrArray rf, int tableLocation,
7979
this.gdef = gdef;
8080
this.unitsPerEm = unitsPerEm;
8181
}
82-
82+
8383
public Glyph getGlyph(int index) {
8484
return indexGlyphMap.get(index);
8585
}
86-
86+
8787
public OpenTableLookup getLookupTable(int idx) {
8888
if (idx < 0 || idx >= lookupList.size()) {
8989
return null;
@@ -94,11 +94,11 @@ public OpenTableLookup getLookupTable(int idx) {
9494
public List<ScriptRecord> getScriptRecords() {
9595
return scriptsType.getScriptRecords();
9696
}
97-
97+
9898
public List<FeatureRecord> getFeatureRecords() {
9999
return featuresType.getRecords();
100100
}
101-
101+
102102
public List<FeatureRecord> getFeatures(String[] scripts, String language) {
103103
LanguageRecord rec = scriptsType.getLanguageRecord(scripts, language);
104104
if (rec == null) {
@@ -110,7 +110,7 @@ public List<FeatureRecord> getFeatures(String[] scripts, String language) {
110110
}
111111
return ret;
112112
}
113-
113+
114114
public List<FeatureRecord> getSpecificFeatures(List<FeatureRecord> features, String[] specific) {
115115
if (specific == null) {
116116
return features;
@@ -128,14 +128,14 @@ public List<FeatureRecord> getSpecificFeatures(List<FeatureRecord> features, Str
128128
}
129129
return recs;
130130
}
131-
131+
132132
public FeatureRecord getRequiredFeature(String[] scripts, String language) {
133133
LanguageRecord rec = scriptsType.getLanguageRecord(scripts, language);
134134
if (rec == null)
135135
return null;
136136
return featuresType.getRecord(rec.featureRequired);
137137
}
138-
138+
139139
public List<OpenTableLookup> getLookups(FeatureRecord[] features) {
140140
IntHashtable hash = new IntHashtable();
141141
for (FeatureRecord rec : features) {
@@ -158,7 +158,7 @@ public List<OpenTableLookup> getLookups(FeatureRecord feature) {
158158
}
159159
return ret;
160160
}
161-
161+
162162
public boolean isSkip(int glyph, int flag) {
163163
return gdef.isSkip(glyph, flag);
164164
}
@@ -183,18 +183,18 @@ public LanguageRecord getLanguageRecord(String otfScriptTag) {
183183
}
184184
return languageRecord;
185185
}
186-
186+
187187
protected abstract OpenTableLookup readLookupTable(int lookupType, int lookupFlag, int[] subTableLocations)
188188
throws java.io.IOException;
189189

190190
protected final OtfClass readClassDefinition(int classLocation) throws java.io.IOException {
191191
return OtfClass.create(rf, classLocation);
192192
}
193-
193+
194194
protected final int[] readUShortArray(int size, int location) throws java.io.IOException {
195195
return OtfReadCommon.readUShortArray(rf, size, location);
196196
}
197-
197+
198198
protected final int[] readUShortArray(int size) throws java.io.IOException {
199199
return OtfReadCommon.readUShortArray(rf, size);
200200
}
@@ -255,6 +255,9 @@ private void readLookupListTable(int lookupListTableLocation) throws java.io.IOE
255255
int[] lookupTableLocations = readUShortArray(lookupCount, lookupListTableLocation);
256256
// read LookUp tables
257257
for (int lookupLocation : lookupTableLocations) {
258+
if (lookupLocation == 0) { // be tolerant to NULL offset in LookupList table
259+
continue;
260+
}
258261
readLookupTable(lookupLocation);
259262
}
260263
}

0 commit comments

Comments
 (0)