{"record":{"id":"f5ed12db3b90d425","repo":"mozilla/pdf.js","slug":"maxp-table-has-a-wrong-version-number","errorCode":null,"errorMessage":"\"maxp\" table has a wrong version number","messagePattern":"\"maxp\" table has a wrong version number","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/fonts.js","lineNumber":2828,"sourceCode":"      }\n    }\n\n    font.pos = (font.start || 0) + tables.maxp.offset;\n    let version = font.getInt32();\n    const numGlyphs = numGlyphsFromCFF ?? font.getUint16();\n    if (version === 0x00005000 && tables.maxp.length !== 6) {\n      tables.maxp.data = tables.maxp.data.subarray(0, 6);\n      tables.maxp.length = 6;\n    }\n\n    if (version !== 0x00010000 && version !== 0x00005000) {\n      // https://learn.microsoft.com/en-us/typography/opentype/spec/maxp\n      if (tables.maxp.length === 6) {\n        version = 0x0005000;\n      } else if (tables.maxp.length >= 32) {\n        version = 0x00010000;\n      } else {\n        throw new FormatError(`\"maxp\" table has a wrong version number`);\n      }\n      writeUint32(tables.maxp.data, 0, version);\n    }\n\n    let isGlyphLocationsLong = int16(\n      tables.head.data[50],\n      tables.head.data[51]\n    );\n    if (tables.loca) {\n      const locaLength = isGlyphLocationsLong\n        ? (numGlyphs + 1) * 4\n        : (numGlyphs + 1) * 2;\n      if (tables.loca.length !== locaLength) {\n        warn(\"Incorrect 'loca' table length -- attempting to fix it.\");\n        // The length of the loca table is wrong (see #13425), so we check if we\n        // have enough space to fix it.\n        const sortedTables = Object.values(tables)\n          .filter(Boolean)","sourceCodeStart":2810,"sourceCodeEnd":2846,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/fonts.js#L2810-L2846","documentation":"Thrown when the maxp table's version field is neither 0x00010000 (version 1.0 for TrueType, 32+ bytes) nor 0x00005000 (version 0.5 for CFF, 6 bytes), AND the table length doesn't allow unambiguous inference of the correct version. When the length is 6, pdf.js assumes version 0.5; when >= 32, it assumes 1.0; otherwise it throws.","triggerScenarios":"The version read from tables.maxp.data via font.getInt32() is not 0x00010000 or 0x00005000. The code then checks: if length===6 → set 0x00005000, else if length>=32 → set 0x00010000, else throw. A maxp table with a bad version and a length between 7 and 31 bytes triggers the throw.","commonSituations":"A maxp table truncated to a non-standard size (e.g., 16 bytes) with a corrupt version field. Fonts produced by buggy generators that write an incorrect version number. Byte-level corruption of the maxp table's first 4 bytes. Experimental or non-conformant font formats.","solutions":["Rebuild the font with fonttools to regenerate a correct maxp table with the proper version for its type.","Ensure TrueType fonts use maxp version 0x00010000 (length >= 32) and CFF fonts use 0x00005000 (length 6).","Replace the corrupt font with a known-good copy.","Run ots-sanitize to catch maxp version/length mismatches before embedding."],"exampleFix":"# fix maxp version with fonttools\nfrom fontTools import ttLib\nfont = ttLib.TTFont('broken.ttf')\nif hasattr(font, 'glyf'):  # TrueType\n    font['maxp'].tableVersion = 0x00010000\nelse:  # CFF\n    font['maxp'].tableVersion = 0x00005000\nfont.save('fixed.ttf')","handlingStrategy":"validation","validationCode":"// Server-side: verify maxp version matches table type\n// from fontTools import ttLib\n// font = ttLib.TTFont('font.ttf')\n// maxp = font['maxp']\n// isTrueType = 'glyf' in font\n// expectedVersion = 0x00010000 if isTrueType else 0x00005000\n// if maxp.tableVersion != expectedVersion:\n//     print(f'maxp version mismatch: {maxp.tableVersion:#x}')\n","typeGuard":null,"tryCatchPattern":"try {\n  await page.render(renderParams).promise;\n} catch (err) {\n  if (err.message?.includes('\"maxp\" table has a wrong version number')) {\n    console.error('Font maxp table version/length mismatch; rebuild the font.');\n  } else { throw err; }\n}","preventionTips":["Use fonttools to rebuild fonts — it writes correct maxp versions automatically.","Ensure TrueType fonts use maxp version 0x00010000 (>= 32 bytes); CFF fonts use 0x00005000 (6 bytes).","Run ots-sanitize to catch maxp version/length mismatches."],"tags":["font","maxp-table","font-version","truetype","opentype","format-error"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}