bpampuch / pdfmake

Client/server side PDF printing in pure JavaScript
http://pdfmake.org
Other
11.71k stars 2.04k forks source link

"Trying to access beyond buffer length" Error when trying to create with specific font #2810

Open Vikeo opened 1 day ago

Vikeo commented 1 day ago

Trying to use the font Arimo but I get this error.

This is the code I'm running:

  const arimoFonts = {
    normal: `fonts/Arimo/Arimo-Regular.ttf`,
    bold: `fonts/Arimo/Arimo-Bold.ttf`,
    italics: `fonts/Arimo/Arimo-Italic.ttf`,
    bolditalics: `fonts/Arimo/Arimo-BoldItalic.ttf`,
  };

  const fontValues = Object.values(arimoFonts);

  const result = pdfMake.createPdf(
    data,
    tableLayouts,
    {
      arimo: arimoFonts,
    },
    await vfs_fonts("arimo", fontValues)
  );
  return result;

Stacktrace:

(node:68737) UnhandledPromiseRejectionWarning: RangeError: Trying to access beyond buffer length
    at checkOffset (repo/node_modules/pdfmake/build/pdfmake.js:2513:36)
    at Uint8Array.readInt16BE (repo/node_modules/pdfmake/build/pdfmake.js:2631:18)
    at DecodeStream.<computed> [as readInt16BE] (repo/node_modules/pdfmake/build/pdfmake.js:500:33)
    at NumberT.decode (repo/node_modules/pdfmake/build/pdfmake.js:807:36)
    at Struct._parseFields (repo/node_modules/pdfmake/build/pdfmake.js:1260:20)
    at Struct.decode (repo/node_modules/pdfmake/build/pdfmake.js:1226:10)
    at TTFGlyph._getCBox (repo/node_modules/pdfmake/build/pdfmake.js:65155:28)
    at TTFGlyph._getMetrics (repo/node_modules/pdfmake/build/pdfmake.js:65352:21)
    at TTFGlyph.get (repo/node_modules/pdfmake/build/pdfmake.js:65067:19)
    at TTFGlyph.descriptor.get (repo/node_modules/pdfmake/build/pdfmake.js:55707:23)
    at repo/node_modules/pdfmake/build/pdfmake.js:64544:38
    at Array.map (<anonymous>)
    at LayoutEngine.position (repo/node_modules/pdfmake/build/pdfmake.js:64543:42)
    at LayoutEngine.layout (repo/node_modules/pdfmake/build/pdfmake.js:64527:10)
    at TTFFont.layout (repo/node_modules/pdfmake/build/pdfmake.js:67129:31)
    at EmbeddedFont.layoutRun (repo/node_modules/pdfmake/build/pdfmake.js:70941:25)
    at EmbeddedFont.layoutCached (repo/node_modules/pdfmake/build/pdfmake.js:70961:20)
    at EmbeddedFont.layout (repo/node_modules/pdfmake/build/pdfmake.js:70981:24)
    at EmbeddedFont.widthOfString (repo/node_modules/pdfmake/build/pdfmake.js:71017:22)
    at widthOfString (repo/node_modules/pdfmake/build/pdfmake.js:55447:14)
    at repo/node_modules/pdfmake/build/pdfmake.js:55405:16
    at Array.forEach (<anonymous>)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:68737) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:68737) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Got any ideas as to how to fix?

liborm85 commented 1 day ago

Tested Arimo font and it works without error. Attach full runnable example for reproduce issue.