Skip to content

Commit 9af6e05

Browse files
committed
Merge pull request mozilla#2615 from vyv03354/master
Fixes CFF parser failure when CharStrings contains cntrmask
2 parents df731e7 + a254de8 commit 9af6e05

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/fonts.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5379,29 +5379,29 @@ var CFFFont = (function CFFFontClosure() {
53795379
var CFFParser = (function CFFParserClosure() {
53805380
var CharstringValidationData = [
53815381
null,
5382-
{ id: 'hstem', min: 2, resetStack: true },
5382+
{ id: 'hstem', min: 2, resetStack: true, stem: true },
53835383
null,
5384-
{ id: 'vstem', min: 2, resetStack: true },
5384+
{ id: 'vstem', min: 2, resetStack: true, stem: true },
53855385
{ id: 'vmoveto', min: 1, resetStack: true },
53865386
{ id: 'rlineto', min: 2, resetStack: true },
53875387
{ id: 'hlineto', min: 1, resetStack: true },
53885388
{ id: 'vlineto', min: 1, resetStack: true },
53895389
{ id: 'rrcurveto', min: 6, resetStack: true },
53905390
null,
53915391
{ id: 'callsubr', min: 1, undefStack: true },
5392-
{ id: 'return', min: 0, resetStack: true },
5392+
{ id: 'return', min: 0, undefStack: true },
53935393
null, // 12
53945394
null,
53955395
null, // endchar
53965396
null,
53975397
null,
53985398
null,
5399-
{ id: 'hstemhm', min: 2, resetStack: true },
5399+
{ id: 'hstemhm', min: 2, resetStack: true, stem: true },
54005400
null, // hintmask
54015401
null, // cntrmask
54025402
{ id: 'rmoveto', min: 2, resetStack: true },
54035403
{ id: 'hmoveto', min: 1, resetStack: true },
5404-
{ id: 'vstemhm', min: 2, resetStack: true },
5404+
{ id: 'vstemhm', min: 2, resetStack: true, stem: true },
54055405
{ id: 'rcurveline', min: 8, resetStack: true },
54065406
{ id: 'rlinecurve', min: 8, resetStack: true },
54075407
{ id: 'vvcurveto', min: 4, resetStack: true },
@@ -5417,7 +5417,7 @@ var CFFParser = (function CFFParserClosure() {
54175417
null,
54185418
{ id: 'and', min: 2, stackDelta: -1 },
54195419
{ id: 'or', min: 2, stackDelta: -1 },
5420-
{ id: 'not', min: 2, stackDelta: -1 },
5420+
{ id: 'not', min: 1, stackDelta: 0 },
54215421
null,
54225422
null,
54235423
null,
@@ -5737,9 +5737,6 @@ var CFFParser = (function CFFParserClosure() {
57375737
} else if (value == 255) { // number (32 bit)
57385738
j += 4;
57395739
stackSize++;
5740-
} else if (value == 18 || value == 23) {
5741-
hints += stackSize >> 1;
5742-
validationCommand = CharstringValidationData[value];
57435740
} else if (value == 19 || value == 20) {
57445741
hints += stackSize >> 1;
57455742
j += (hints + 7) >> 3; // skipping right amount of hints flag data
@@ -5748,6 +5745,9 @@ var CFFParser = (function CFFParserClosure() {
57485745
validationCommand = CharstringValidationData[value];
57495746
}
57505747
if (validationCommand) {
5748+
if (validationCommand.stem) {
5749+
hints += stackSize >> 1;
5750+
}
57515751
if ('min' in validationCommand) {
57525752
if (!undefStack && stackSize < validationCommand.min) {
57535753
warn('Not enough parameters for ' + validationCommand.id +

test/unit/font_spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,28 @@ describe('font', function() {
9696
expect(topDict.getByName('Private')).toEqual([45, 102]);
9797
});
9898

99+
it('parses a CharString having cntrmask', function() {
100+
var bytes = new Uint8Array([0, 1, // count
101+
1, // offsetSize
102+
0, // offset[0]
103+
38, // end
104+
149, 149, 149, 149, 149, 149, 149, 149,
105+
149, 149, 149, 149, 149, 149, 149, 149,
106+
1, // hstem
107+
149, 149, 149, 149, 149, 149, 149, 149,
108+
149, 149, 149, 149, 149, 149, 149, 149,
109+
3, // vstem
110+
20, // cntrmask
111+
22, 22, // fail if misparsed as hmoveto
112+
14 // endchar
113+
]);
114+
parser.bytes = bytes;
115+
var charStrings = parser.parseCharStrings(0);
116+
expect(charStrings.count).toEqual(1);
117+
// shoudn't be sanitized
118+
expect(charStrings.get(0).length).toEqual(38);
119+
});
120+
99121
it('parses predefined charsets', function() {
100122
var charset = parser.parseCharsets(0, 0, null, true);
101123
expect(charset.predefined).toEqual(true);

0 commit comments

Comments
 (0)