mozilla/pdf.js · error · FormatError
Too many arguments
Error message
Too many arguments
What it means
Thrown by EvaluatorPreprocessor while accumulating operands for an operator when the argument stack exceeds 33 entries without a matching operator consuming them. The PDF spec caps operands at 31 (plus margin); exceeding this indicates a malformed stream where operands pile up, typically due to missing operator tokens or corrupt numeric data. The guard prevents unbounded memory growth and infinite accumulation.
Source
Thrown at src/core/evaluator.js:5473
// TODO figure out how to type-check vararg functions
this.preprocessCommand(fn, args);
operation.fn = fn;
operation.args = args;
return true;
}
if (obj === EOF) {
return false; // no more commands
}
// argument
if (obj !== null) {
if (args === null) {
args = [];
}
args.push(obj);
if (args.length > 33) {
throw new FormatError("Too many arguments");
}
}
}
}
preprocessCommand(fn, args) {
switch (fn | 0) {
case OPS.save:
this.stateManager.save();
break;
case OPS.restore:
this.stateManager.restore();
break;
case OPS.transform:
this.stateManager.transform(args);
break;
}
}View on GitHub (pinned to 5903d58d58)
Solutions
- Re-acquire the PDF (re-download, re-export) to rule out transfer corruption.
- Repair with qpdf or Ghostscript to re-encode the content stream and remove corrupt tokens.
- Isolate the page with per-page try/catch; render remaining pages normally.
- If authoring, ensure your content-stream writer flushes operators at least every 31 operands.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await page.render({ canvasContext, viewport });
} catch (e) {
if (e.name === 'FormatError' && /Too many arguments/.test(e.message)) {
// content stream corrupt — operand overflow
} else throw e;
} Prevention
- Verify PDF integrity (re-download, MD5 check) to rule out transfer corruption of content streams.
- Repair with qpdf or Ghostscript to re-encode content streams.
- When authoring content streams, flush operators at least every 31 operands to stay within the spec cap.
When it happens
Trigger: A content stream where 34+ operands are pushed without any operator consuming them — e.g. a long run of numbers due to a missing 'm'/'l'/'scn' operator, or a corrupt stream decoded into a sea of numeric tokens. Fires during the operand-collection loop in EvaluatorPreprocessor.read().
Common situations: Content streams corrupted by transfer errors, decompression faults producing garbage tokens, or generators that wrote large numeric arrays without interleaving operators. Also seen when a Flate stream is mis-decoded due to upstream corruption, yielding spurious numeric tokens.
Related errors
- Invalid ${partialMsg}
- Invalid entry in 'Differences' array: ${data}
- Encoding is not a Name nor a Dict
- Max size of CID is 65,535
- invalid font Subtype
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/48ab3d635ac8b40d.
Report an issue: GitHub.