Skip to content

Commit a254de8

Browse files
committed
CFF parser didn't count hints defined by hstem/vstem
1 parent f7a0d6c commit a254de8

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
@@ -5453,29 +5453,29 @@ var CFFFont = (function CFFFontClosure() {
54535453
var CFFParser = (function CFFParserClosure() {
54545454
var CharstringValidationData = [
54555455
null,
5456-
{ id: 'hstem', min: 2, resetStack: true },
5456+
{ id: 'hstem', min: 2, resetStack: true, stem: true },
54575457
null,
5458-
{ id: 'vstem', min: 2, resetStack: true },
5458+
{ id: 'vstem', min: 2, resetStack: true, stem: true },
54595459
{ id: 'vmoveto', min: 1, resetStack: true },
54605460
{ id: 'rlineto', min: 2, resetStack: true },
54615461
{ id: 'hlineto', min: 1, resetStack: true },
54625462
{ id: 'vlineto', min: 1, resetStack: true },
54635463
{ id: 'rrcurveto', min: 6, resetStack: true },
54645464
null,
54655465
{ id: 'callsubr', min: 1, undefStack: true },
5466-
{ id: 'return', min: 0, resetStack: true },
5466+
{ id: 'return', min: 0, undefStack: true },
54675467
null, // 12
54685468
null,
54695469
null, // endchar
54705470
null,
54715471
null,
54725472
null,
5473-
{ id: 'hstemhm', min: 2, resetStack: true },
5473+
{ id: 'hstemhm', min: 2, resetStack: true, stem: true },
54745474
null, // hintmask
54755475
null, // cntrmask
54765476
{ id: 'rmoveto', min: 2, resetStack: true },
54775477
{ id: 'hmoveto', min: 1, resetStack: true },
5478-
{ id: 'vstemhm', min: 2, resetStack: true },
5478+
{ id: 'vstemhm', min: 2, resetStack: true, stem: true },
54795479
{ id: 'rcurveline', min: 8, resetStack: true },
54805480
{ id: 'rlinecurve', min: 8, resetStack: true },
54815481
{ id: 'vvcurveto', min: 4, resetStack: true },
@@ -5491,7 +5491,7 @@ var CFFParser = (function CFFParserClosure() {
54915491
null,
54925492
{ id: 'and', min: 2, stackDelta: -1 },
54935493
{ id: 'or', min: 2, stackDelta: -1 },
5494-
{ id: 'not', min: 2, stackDelta: -1 },
5494+
{ id: 'not', min: 1, stackDelta: 0 },
54955495
null,
54965496
null,
54975497
null,
@@ -5811,9 +5811,6 @@ var CFFParser = (function CFFParserClosure() {
58115811
} else if (value == 255) { // number (32 bit)
58125812
j += 4;
58135813
stackSize++;
5814-
} else if (value == 18 || value == 23) {
5815-
hints += stackSize >> 1;
5816-
validationCommand = CharstringValidationData[value];
58175814
} else if (value == 19 || value == 20) {
58185815
hints += stackSize >> 1;
58195816
j += (hints + 7) >> 3; // skipping right amount of hints flag data
@@ -5822,6 +5819,9 @@ var CFFParser = (function CFFParserClosure() {
58225819
validationCommand = CharstringValidationData[value];
58235820
}
58245821
if (validationCommand) {
5822+
if (validationCommand.stem) {
5823+
hints += stackSize >> 1;
5824+
}
58255825
if ('min' in validationCommand) {
58265826
if (!undefStack && stackSize < validationCommand.min) {
58275827
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)