Browse Source

Fix invalid version number in truetype 'head' table

mduan 12 years ago
parent
commit
0527b8bc8d
  1. 19
      src/fonts.js
  2. 1
      test/pdfs/issue2531.pdf.link
  3. 8
      test/test_manifest.json

19
src/fonts.js

@ -3254,6 +3254,21 @@ var Font = (function FontClosure() { @@ -3254,6 +3254,21 @@ var Font = (function FontClosure() {
return glyf.length;
}
function sanitizeHead(head) {
var data = head.data;
// Validate version:
// Should always be 0x00010000
var version = int32([data[0], data[1], data[2], data[3]]);
if (version >> 16 !== 1) {
info('Invalid version in data type: ' + version);
data[0] = 0;
data[1] = 1;
data[2] = 0;
data[3] = 0;
}
}
function sanitizeGlyphLocations(loca, glyf, numGlyphs,
isGlyphLocationsLong) {
var itemSize, itemDecode, itemEncode;
@ -3678,6 +3693,10 @@ var Font = (function FontClosure() { @@ -3678,6 +3693,10 @@ var Font = (function FontClosure() {
sanitizeTTPrograms(fpgm, prep);
if (head) {
sanitizeHead(head);
}
var isGlyphLocationsLong = int16([head.data[50], head.data[51]]);
if (head && loca && glyf) {
sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong);

1
test/pdfs/issue2531.pdf.link

@ -0,0 +1 @@ @@ -0,0 +1 @@
http://www.rcjohnso.com/Looper/Looper.pdf

8
test/test_manifest.json

@ -30,6 +30,14 @@ @@ -30,6 +30,14 @@
"rounds": 1,
"type": "eq"
},
{ "id": "issue2531",
"file": "pdfs/issue2531.pdf",
"md5": "c58e6642d8a6e2ddd5e07a543ef8f30d",
"link": true,
"rounds": 1,
"pageLimit": 4,
"type": "eq"
},
{ "id": "html5-canvas-cheat-sheet-load",
"file": "pdfs/canvas.pdf",
"md5": "59510028561daf62e00bf9f6f066b033",

Loading…
Cancel
Save