diff --git a/src/core/fonts.js b/src/core/fonts.js index 7c8b1c0d1..24ed0139c 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -2117,6 +2117,14 @@ class Font { break; } + // If the last offset is 0 in the loca table then we can't compute the + // endOffset for the last glyph. So in such a case we set the endOffset + // to the end of the data (fixes issue #17671). + const last = locaEntries.at(-2); + if (last.offset !== 0 && last.endOffset === 0) { + last.endOffset = oldGlyfDataLength; + } + const missingGlyphs = Object.create(null); let writeOffset = 0; itemEncode(locaData, 0, writeOffset); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index fbc0cf99c..cd967df1d 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -628,3 +628,4 @@ !issue17492.pdf !issue17540.pdf !bug1669097.pdf +!issue17671.pdf diff --git a/test/pdfs/issue17671.pdf b/test/pdfs/issue17671.pdf new file mode 100755 index 000000000..5a785ed93 Binary files /dev/null and b/test/pdfs/issue17671.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 016082e89..24f309967 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -9675,5 +9675,12 @@ "id": null } } + }, + { + "id": "issue17671", + "file": "pdfs/issue17671.pdf", + "md5": "407695b36b4611bc7c501a891c8a4b28", + "rounds": 1, + "type": "eq" } ]