Skip to content

tokenizer: a token id past the cap is refused at load - #3033

Merged
ashhart merged 2 commits into
mainfrom
security/tokenizer-id-cap
Nov 13, 2026
Merged

ashhart merged 2 commits into
mainfrom
security/tokenizer-id-cap

Conversation

@ashhart

@ashhart ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

What this changes

Before: a token id near 2^32 in tokenizer.json sized a table of tens of gigabytes. After: an id above 16,777,215 is refused when the file loads.

  • Issue: n/a. SECURITY.md asks for private reports, so there is no public issue.
  • Stacked on: main.
  • atc overlap --json: not run.

Checks on this head

  • Head commit: 77328b238bb6f644c9257116d4c1a9c621d553ad
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 345 on the base, 345 on this head, 0 new.
  • Tests run, with the command and pass, fail and skip counts:
    • zig fmt --check on 3 files: passes
    • git diff --check: passes
    • zig test --dep sys -Mroot=zig/src/core/tokenizer/tokenizer.zig -Msys=zig/src/platform/sys.zig -lc (the tokenizer module has no host step of its own): All 55 tests passed.
    • zig build test-server-cpu: 5/5 steps succeeded; 1325/1332 tests passed (7 skipped)
    • zig build test-golden test-server-security test-pull-security: 76/76 steps succeeded; 32/32 tests passed
  • New tests:
    • security: a tokenizer file cannot name a token id that sizes a huge table
  • CI: runs on this push.
  • Not run, and why: Not run against every shipped tokenizer: the cap is far above any real vocabulary. zig build test and every step that runs on a GPU were not run: this Mac's GPU was serving a model, and no CUDA, ROCm or Intel hardware was available.

Receipt

n/a. This change cannot reach inference: it is a load-time check of the tokenizer file. A tokenizer that loads today has no such id.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. Main with only this branch's tests added, the same zig test command: exit 1. 54 passed, 1 failed: the new test.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

Notes for the reviewer

  • Main already guards the id + 1 overflow. This adds the cap.
  • The Split regex's step budget and the template parser's depth limit are not part of this.

Suggested changelog line

Tokenizer: a token id past the cap is refused at load.

@ashhart
ashhart marked this pull request as ready for review November 12, 2026 17:36
@ashhart

ashhart commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner Author

Review: ready. The cap is checked at both load paths (model.zig and tokenizer.zig), with a backstop in IdTable.put; no real vocabulary is near 2^24. One follow-up, not blocking: no CI step runs the tokenizer's own tests apart from the EOS-policy filter, so the new test doesn't run in CI yet.

  • Synthena (Ash's Agent)

An id near 2^32 in tokenizer.json sized a table of tens of gigabytes. Ids are capped when the file loads.
@ashhart
ashhart force-pushed the security/tokenizer-id-cap branch from 77328b2 to 5897258 Compare November 13, 2026 00:05
@ashhart
ashhart merged commit 0fed2e4 into main Nov 13, 2026
2 of 10 checks passed
@ashhart
ashhart deleted the security/tokenizer-id-cap branch November 13, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant