Skip to content
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
39 changes: 29 additions & 10 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2702,13 +2702,36 @@ class Font {
writeUint32(tables.maxp.data, 0, version);
}

let isGlyphLocationsLong = int16(
tables.head.data[50],
tables.head.data[51]
);
if (tables.loca) {
const locaLength = isGlyphLocationsLong
? (numGlyphs + 1) * 4
: (numGlyphs + 1) * 2;
if (tables.loca.length !== locaLength) {
warn("Incorrect 'loca' table length -- attempting to fix it.");
// The length of the loca table is wrong (see #13425), so we check if we
// have enough space to fix it.
const sortedTables = Object.values(tables)
.filter(Boolean)
.sort((a, b) => a.offset - b.offset);
const locaIndex = sortedTables.indexOf(tables.loca);
const nextTable = sortedTables[locaIndex + 1] || null;
if (nextTable && tables.loca.offset + locaLength < nextTable.offset) {
const previousPos = font.pos;
font.pos = font.start || 0;
font.skip(tables.loca.offset);
tables.loca.data = font.getBytes(locaLength);
tables.loca.length = locaLength;
font.pos = previousPos;
}
}
}

if (properties.scaleFactors?.length === numGlyphs && isTrueType) {
const { scaleFactors } = properties;
const isGlyphLocationsLong = int16(
tables.head.data[50],
tables.head.data[51]
);

const glyphs = new GlyfTable({
glyfTable: tables.glyf.data,
isGlyphLocationsLong,
Expand All @@ -2723,7 +2746,7 @@ class Font {

if (isLocationLong !== !!isGlyphLocationsLong) {
tables.head.data[50] = 0;
tables.head.data[51] = isLocationLong ? 1 : 0;
isGlyphLocationsLong = tables.head.data[51] = isLocationLong ? 1 : 0;
}

const metrics = tables.hmtx.data;
Expand Down Expand Up @@ -2801,10 +2824,6 @@ class Font {

let missingGlyphs = Object.create(null);
if (isTrueType) {
const isGlyphLocationsLong = int16(
tables.head.data[50],
tables.head.data[51]
);
const glyphsInfo = sanitizeGlyphLocations(
tables.loca,
tables.glyf,
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue13425.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/6529459/20200927_204903_509.pdf
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13115,5 +13115,13 @@
"md5": "b85c798b9a4cc2cd4337d335321cc612",
"rounds": 1,
"type": "eq"
},
{
"id": "issue13425",
"file": "pdfs/issue13425.pdf",
"md5": "36854e6ad43b8e0446d3d64e8f2950bf",
"rounds": 1,
"link": true,
"type": "eq"
}
]