Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore reserved commands when parsing operands in CFFParser_parseDict, instead of just rejecting the entire font (bug 1308536) #7698

Merged
merged 1 commit into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/core/cff_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ var CFFParser = (function CFFParserClosure() {
} else if (value >= 251 && value <= 254) {
return -((value - 251) * 256) - dict[pos++] - 108;
} else {
error('255 is not a valid DICT command');
warn('CFFParser_parseDict: "' + value + '" is a reserved command.');
return NaN;
}
return -1;
}

function parseFloatOperand() {
Expand Down Expand Up @@ -1000,19 +1000,22 @@ var CFFDict = (function CFFDictClosure() {
if (!(key in this.keyToNameMap)) {
return false;
}
var valueLength = value.length;
// ignore empty values
if (value.length === 0) {
if (valueLength === 0) {
return true;
}
// Ignore invalid values (fixes bug1068432.pdf and bug1308536.pdf).
for (var i = 0; i < valueLength; i++) {
if (isNaN(value[i])) {
warn('Invalid CFFDict value: "' + value + '" for key "' + key + '".');
return true;
}
}
var type = this.types[key];
// remove the array wrapping these types of values
if (type === 'num' || type === 'sid' || type === 'offset') {
value = value[0];
// Ignore invalid values (fixes bug 1068432).
if (isNaN(value)) {
warn('Invalid CFFDict value: ' + value + ', for key: ' + key + '.');
return true;
}
}
this.values[key] = value;
return true;
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
!bug1068432.pdf
!bug1146106.pdf
!bug1252420.pdf
!bug1308536.pdf
!issue5564_reduced.pdf
!canvas.pdf
!bug1132849.pdf
Expand Down
Binary file added test/pdfs/bug1308536.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,13 @@
"link": false,
"type": "load"
},
{ "id": "bug1308536",
"file": "pdfs/bug1308536.pdf",
"md5": "cc2258981e33ad8d96acbf87318716d5",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "bug1252420",
"file": "pdfs/bug1252420.pdf",
"md5": "f21c911b9b655972b06ef782a1fa6a17",
Expand Down
35 changes: 31 additions & 4 deletions test/unit/cff_parser_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* globals describe, it, expect, beforeAll, afterAll, Stream, CFFParser,
SEAC_ANALYSIS_ENABLED, CFFIndex, CFFStrings, CFFCompiler */
/* globals describe, it, expect, beforeAll, afterAll, beforeEach, afterEach,
Stream, CFFParser, SEAC_ANALYSIS_ENABLED, CFFIndex, CFFStrings,
CFFCompiler */

'use strict';

Expand Down Expand Up @@ -33,14 +34,22 @@ describe('CFFParser', function() {
fontArr.push(parseInt(hex, 16));
}
fontData = new Stream(fontArr);
done();
});

afterAll(function () {
fontData = null;
});

beforeEach(function (done) {
parser = new CFFParser(fontData, {}, SEAC_ANALYSIS_ENABLED);
cff = parser.parse();
done();
});

afterAll(function () {
fontData = parser = cff = null;
afterEach(function (done) {
parser = cff = null;
done();
});

it('parses header', function() {
Expand Down Expand Up @@ -104,6 +113,24 @@ describe('CFFParser', function() {
expect(topDict.getByName('UnderlinePosition')).toEqual(defaultValue);
});

it('ignores reserved commands in parseDict, and refuses to add privateDict ' +
'keys with invalid values (bug 1308536)', function () {
var bytes = new Uint8Array([
64, 39, 31, 30, 252, 114, 137, 115, 79, 30, 197, 119, 2, 99, 127, 6
]);
parser.bytes = bytes;
var topDict = cff.topDict;
topDict.setByName('Private', [bytes.length, 0]);

var parsePrivateDict = function () {
parser.parsePrivateDict(topDict);
};
expect(parsePrivateDict).not.toThrow();

var privateDict = topDict.privateDict;
expect(privateDict.getByName('BlueValues')).toBeNull();
});

it('parses a CharString having cntrmask', function() {
var bytes = new Uint8Array([0, 1, // count
1, // offsetSize
Expand Down