mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-24 08:55:48 +02:00
Merge pull request #20538 from calixteman/issue13425
Fix the loca table length when there is enough space for it
This commit is contained in:
commit
1990fa7cd0
@ -2702,13 +2702,36 @@ class Font {
|
|||||||
writeUint32(tables.maxp.data, 0, version);
|
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) {
|
if (properties.scaleFactors?.length === numGlyphs && isTrueType) {
|
||||||
const { scaleFactors } = properties;
|
const { scaleFactors } = properties;
|
||||||
const isGlyphLocationsLong = int16(
|
|
||||||
tables.head.data[50],
|
|
||||||
tables.head.data[51]
|
|
||||||
);
|
|
||||||
|
|
||||||
const glyphs = new GlyfTable({
|
const glyphs = new GlyfTable({
|
||||||
glyfTable: tables.glyf.data,
|
glyfTable: tables.glyf.data,
|
||||||
isGlyphLocationsLong,
|
isGlyphLocationsLong,
|
||||||
@ -2723,7 +2746,7 @@ class Font {
|
|||||||
|
|
||||||
if (isLocationLong !== !!isGlyphLocationsLong) {
|
if (isLocationLong !== !!isGlyphLocationsLong) {
|
||||||
tables.head.data[50] = 0;
|
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;
|
const metrics = tables.hmtx.data;
|
||||||
@ -2801,10 +2824,6 @@ class Font {
|
|||||||
|
|
||||||
let missingGlyphs = Object.create(null);
|
let missingGlyphs = Object.create(null);
|
||||||
if (isTrueType) {
|
if (isTrueType) {
|
||||||
const isGlyphLocationsLong = int16(
|
|
||||||
tables.head.data[50],
|
|
||||||
tables.head.data[51]
|
|
||||||
);
|
|
||||||
const glyphsInfo = sanitizeGlyphLocations(
|
const glyphsInfo = sanitizeGlyphLocations(
|
||||||
tables.loca,
|
tables.loca,
|
||||||
tables.glyf,
|
tables.glyf,
|
||||||
|
|||||||
1
test/pdfs/issue13425.pdf.link
Normal file
1
test/pdfs/issue13425.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://github.com/mozilla/pdf.js/files/6529459/20200927_204903_509.pdf
|
||||||
@ -13115,5 +13115,13 @@
|
|||||||
"md5": "b85c798b9a4cc2cd4337d335321cc612",
|
"md5": "b85c798b9a4cc2cd4337d335321cc612",
|
||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "issue13425",
|
||||||
|
"file": "pdfs/issue13425.pdf",
|
||||||
|
"md5": "36854e6ad43b8e0446d3d64e8f2950bf",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": true,
|
||||||
|
"type": "eq"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user