1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #9045 from brendandahl/sani-name

Sanitize name index in compile phase of CFF.
This commit is contained in:
Jonas Jenwald 2017-10-24 11:48:03 +02:00 committed by GitHub
commit d71a576b30
5 changed files with 60 additions and 39 deletions

View file

@ -116,6 +116,7 @@
!issue4630.pdf
!issue4909.pdf
!issue5084.pdf
!issue8960_reduced.pdf
!issue5202.pdf
!issue5280.pdf
!issue5677.pdf

Binary file not shown.

View file

@ -773,6 +773,13 @@
"link": false,
"type": "eq"
},
{ "id": "issue8960_reduced",
"file": "pdfs/issue8960_reduced.pdf",
"md5": "12ccf71307f4b5bd4148d5f985ffde07",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "issue5954",
"file": "pdfs/issue5954.pdf",
"md5": "4f60ec0d9bbeec845b681242b8982361",

View file

@ -14,7 +14,7 @@
*/
import {
CFFCompiler, CFFIndex, CFFParser, CFFStrings
CFFCompiler, CFFParser, CFFStrings
} from '../../src/core/cff_parser';
import { SEAC_ANALYSIS_ENABLED } from '../../src/core/fonts';
import { Stream } from '../../src/core/stream';
@ -88,23 +88,6 @@ describe('CFFParser', function() {
expect(names[0]).toEqual('ABCDEF+Times-Roman');
});
it('sanitizes name index', function() {
var index = new CFFIndex();
index.add(['['.charCodeAt(0), 'a'.charCodeAt(0)]);
var names = parser.parseNameIndex(index);
expect(names).toEqual(['_a']);
index = new CFFIndex();
var longName = [];
for (var i = 0; i < 129; i++) {
longName.push(0);
}
index.add(longName);
names = parser.parseNameIndex(index);
expect(names[0].length).toEqual(127);
});
it('parses string index', function() {
var strings = cff.strings;
expect(strings.count).toEqual(3);
@ -368,6 +351,16 @@ describe('CFFParser', function() {
});
describe('CFFCompiler', function() {
function testParser(bytes) {
bytes = new Uint8Array(bytes);
return new CFFParser({
getBytes: () => {
return bytes;
},
}, {}, SEAC_ANALYSIS_ENABLED);
}
it('encodes integers', function() {
var c = new CFFCompiler();
// all the examples from the spec
@ -388,5 +381,24 @@ describe('CFFCompiler', function() {
expect(c.encodeFloat(5e-11)).toEqual([0x1e, 0x5c, 0x11, 0xff]);
});
it('sanitizes name index', function() {
var c = new CFFCompiler();
var nameIndexCompiled = c.compileNameIndex(['[a']);
var parser = testParser(nameIndexCompiled);
var nameIndex = parser.parseIndex(0);
var names = parser.parseNameIndex(nameIndex.obj);
expect(names).toEqual(['_a']);
var longName = '';
for (var i = 0; i < 129; i++) {
longName += '_';
}
nameIndexCompiled = c.compileNameIndex([longName]);
parser = testParser(nameIndexCompiled);
nameIndex = parser.parseIndex(0);
names = parser.parseNameIndex(nameIndex.obj);
expect(names[0].length).toEqual(127);
});
// TODO a lot more compiler tests
});