{"record":{"id":"e083f0476c1f96cf","repo":"mozilla/pdf.js","slug":"writing-to-an-offset-that-is-not-empty","errorCode":null,"errorMessage":"writing to an offset that is not empty","messagePattern":"writing to an offset that is not empty","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/cff_parser.js","lineNumber":1480,"sourceCode":"    }\n    const data = output.data;\n    const dataOffset = this.offsets[key];\n    const size = 5;\n    for (let i = 0, ii = values.length; i < ii; ++i) {\n      const offset0 = i * size + dataOffset;\n      const offset1 = offset0 + 1;\n      const offset2 = offset0 + 2;\n      const offset3 = offset0 + 3;\n      const offset4 = offset0 + 4;\n      // It's easy to screw up offsets so perform this sanity check.\n      if (\n        data[offset0] !== 0x1d ||\n        data[offset1] !== 0 ||\n        data[offset2] !== 0 ||\n        data[offset3] !== 0 ||\n        data[offset4] !== 0\n      ) {\n        throw new FormatError(\"writing to an offset that is not empty\");\n      }\n      const value = values[i];\n      data[offset0] = 0x1d;\n      data[offset1] = (value >> 24) & 0xff;\n      data[offset2] = (value >> 16) & 0xff;\n      data[offset3] = (value >> 8) & 0xff;\n      data[offset4] = value & 0xff;\n    }\n  }\n}\n\n// Takes a CFF and converts it to the binary representation.\nclass CFFCompiler {\n  constructor(cff) {\n    this.cff = cff;\n  }\n\n  compile() {","sourceCodeStart":1462,"sourceCodeEnd":1498,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/cff_parser.js#L1462-L1498","documentation":"Thrown by CFFOffsetTracker.setEntryLocation while writing a 5-byte offset placeholder. The placeholder must be the sentinel byte 0x1d followed by four zero bytes; if those bytes are already non-zero, writing would silently corrupt already-emitted data, so the sanity check aborts.","triggerScenarios":"During CFF compilation, setEntryLocation computes offset positions and finds the target bytes are not the expected 0x1d,0,0,0,0 pattern. This means the placeholder region was overwritten or the computed offset points at the wrong location — an internal compiler state bug.","commonSituations":"A pdf.js internal bug in offset arithmetic (wrong outputLength, double offset adjustment); a malformed font that drives compileDict to emit overlapping placeholders; regressions after changes to the DataBuilder/compileIndex logic.","solutions":["Report the issue to pdf.js with the offending font — this is an internal compiler invariant failure.","Verify that offsetTracker.offset() is applied consistently and that placeholders are emitted exactly once per tracked key.","If patching, ensure no code path writes into the placeholder region between track() and setEntryLocation()."],"exampleFix":"// before (internal: placeholder region already non-zero)\ntracker.setEntryLocation('Subrs', [len], output); // throws\n\n// after (ensure placeholders are zero when written)\nif (\n  data[offset0] === 0x1d &&\n  data[offset1] === 0 &&\n  data[offset2] === 0 &&\n  data[offset3] === 0 &&\n  data[offset4] === 0\n) {\n  tracker.setEntryLocation('Subrs', [len], output);\n}","handlingStrategy":"validation","validationCode":"// Verify the placeholder is still empty before writing.\nfunction placeholderIsEmpty(data, offset0) {\n  return (\n    data[offset0] === 0x1d &&\n    data[offset0 + 1] === 0 &&\n    data[offset0 + 2] === 0 &&\n    data[offset0 + 3] === 0 &&\n    data[offset0 + 4] === 0\n  );\n}","typeGuard":"function isPlaceholderEmpty(data, offset0) {\n  return data[offset0] === 0x1d && data[offset0 + 1] === 0 &&\n    data[offset0 + 2] === 0 && data[offset0 + 3] === 0 &&\n    data[offset0 + 4] === 0;\n}","tryCatchPattern":"try {\n  tracker.setEntryLocation(key, values, output);\n} catch (e) {\n  // Placeholder region was non-zero; internal offset corruption.\n  throw new Error(`Offset placeholder for '${key}' was not empty`);\n}","preventionTips":["Ensure no code writes into placeholder regions between track() and setEntryLocation().","Apply offsetTracker.offset() consistently so computed positions stay valid.","Report unexpected occurrences to pdf.js with the offending font."],"tags":["font","cff","cff-compiler","offset-tracker","internal-api","invariant"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}