[Pkg-javascript-commits] [pdf.js] 80/115: Remove glyph id's outside the range of valid glyphs.
David Prévot
taffit at moszumanska.debian.org
Wed Dec 16 20:03:18 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit 87762afec477b0951681df65e6a8286f9d5a1c6a
Author: Brendan Dahl <brendan.dahl at gmail.com>
Date: Wed Dec 2 16:47:20 2015 -0800
Remove glyph id's outside the range of valid glyphs.
OTS does not like invalid glyph ids in a camp table.
---
src/core/fonts.js | 15 ++++++++++-----
test/pdfs/.gitignore | 1 +
test/pdfs/issue5564_reduced.pdf | Bin 0 -> 1859 bytes
test/test_manifest.json | 10 ++++++++++
4 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/src/core/fonts.js b/src/core/fonts.js
index fef393d..a13a7ea 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -2798,11 +2798,15 @@ var Font = (function FontClosure() {
};
}
- function getRanges(glyphs) {
+ function getRanges(glyphs, numGlyphs) {
// Array.sort() sorts by characters, not numerically, so convert to an
// array of characters.
var codes = [];
for (var charCode in glyphs) {
+ // Remove an invalid glyph ID mappings to make OTS happy.
+ if (glyphs[charCode] >= numGlyphs) {
+ continue;
+ }
codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
}
codes.sort(function fontGetRangesSort(a, b) {
@@ -2831,8 +2835,8 @@ var Font = (function FontClosure() {
return ranges;
}
- function createCmapTable(glyphs) {
- var ranges = getRanges(glyphs);
+ function createCmapTable(glyphs, numGlyphs) {
+ var ranges = getRanges(glyphs, numGlyphs);
var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
var cmap = '\x00\x00' + // version
string16(numTables) + // numTables
@@ -4335,7 +4339,7 @@ var Font = (function FontClosure() {
this.toFontChar = newMapping.toFontChar;
tables.cmap = {
tag: 'cmap',
- data: createCmapTable(newMapping.charCodeToGlyphId)
+ data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
};
if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
@@ -4473,7 +4477,8 @@ var Font = (function FontClosure() {
builder.addTable('OS/2', createOS2Table(properties,
newMapping.charCodeToGlyphId));
// Character to glyphs mapping
- builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
+ builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
+ numGlyphs));
// Font header
builder.addTable('head',
'\x00\x01\x00\x00' + // Version number
diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore
index 38a33eb..49ec4be 100644
--- a/test/pdfs/.gitignore
+++ b/test/pdfs/.gitignore
@@ -22,6 +22,7 @@
!bug1020858.pdf
!bug1050040.pdf
!bug1200096.pdf
+!issue5564_reduced.pdf
!canvas.pdf
!complex_ttf_font.pdf
!extgstate.pdf
diff --git a/test/pdfs/issue5564_reduced.pdf b/test/pdfs/issue5564_reduced.pdf
new file mode 100644
index 0000000..0eddb63
Binary files /dev/null and b/test/pdfs/issue5564_reduced.pdf differ
diff --git a/test/test_manifest.json b/test/test_manifest.json
index 054faf0..3452275 100644
--- a/test/test_manifest.json
+++ b/test/test_manifest.json
@@ -40,6 +40,16 @@
"type": "load",
"about": "PDF with undefined stream length."
},
+ { "id": "issue5564_reduced",
+ "file": "pdfs/issue5564_reduced.pdf",
+ "md5": "097853614b56fc10bfbf7e56daa0c66b",
+ "rounds": 1,
+ "link": false,
+ "firstPage": 1,
+ "lastPage": 1,
+ "type": "eq",
+ "about": "Causes cmap to be created with invalid glyph ids."
+ },
{ "id": "bug946506",
"file": "pdfs/bug946506.pdf",
"md5": "c28911b5c31bdc337c2ce404c5971cfc",
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list