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

  1. Re-acquire the PDF (re-download, re-export) to rule out transfer corruption.
  2. Repair with qpdf or Ghostscript to re-encode the content stream and remove corrupt tokens.
  3. Isolate the page with per-page try/catch; render remaining pages normally.
  4. 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

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


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/48ab3d635ac8b40d. Report an issue: GitHub.