Skip to content

Commit efc928c

Browse files
committed
Improve cmap error state handling
- skip mapping 0xFFFF - include glyphs mapped to gid 0 (missing character) - check that the calculated offset to read a glyph exists in the file (can be caused by a bad subtable definition)
1 parent 24f9319 commit efc928c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/FontLib/Table/Type/cmap.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,28 @@ protected function _parse() {
125125
}
126126

127127
for ($c = $c1; $c <= $c2; $c++) {
128+
if ($c === 0xFFFF) {
129+
continue;
130+
}
131+
128132
if ($ro == 0) {
129133
$gid = ($c + $d) & 0xFFFF;
130134
}
131135
else {
132136
$offset = ($c - $c1) * 2 + $ro;
133137
$offset = $ro_start + 2 * $i + $offset;
134138

135-
$font->seek($offset);
136-
$gid = $font->readUInt16();
139+
$gid = 0;
140+
if ($font->seek($offset) === true) {
141+
$gid = $font->readUInt16();
142+
}
137143

138144
if ($gid != 0) {
139145
$gid = ($gid + $d) & 0xFFFF;
140146
}
141147
}
142148

143-
if ($gid > 0) {
149+
if ($gid >= 0) {
144150
$glyphIndexArray[$c] = $gid;
145151
}
146152
}

0 commit comments

Comments
 (0)