Skip to content

fuzz: cover template and tool parsers and fix Unicode tag scanning - #64

Merged
midagedev merged 1 commit into
midagedev:mainfrom
Burntgogi:contribution/fuzz-parsers-20261012
Oct 12, 2026
Merged

midagedev merged 1 commit into
midagedev:mainfrom
Burntgogi:contribution/fuzz-parsers-20261012

Conversation

@Burntgogi

Copy link
Copy Markdown
Contributor

What and why

Jinja tag scanning can panic when a byte offset lands inside a multibyte character, for example in an unclosed Unicode tag. Compare ASCII closers as bytes and add a FAIL-first regression. Add a standalone, workspace-excluded fuzz/ crate covering Jinja parse/render and the GLM, Qwen, DSML and Hermes streaming scanners, with curated seeds, a dictionary and reproducible instructions.

Closes #8.

The scanner targets check chunk-invariant content/calls, acceptance of malformed streams, dense call indices and JSON object arguments. They collect parsed calls without executing tools. The render target varies contexts over six bounded programs and both float styles. Corpus attributes retain intentional CRLF, control bytes and whitespace.

Code shape

  • No second copy. One shared scanner harness collects results; each format target only selects its API. Existing public parser APIs are reused.
  • Model code holds only architecture facts. No model-specific or GPU code changes.
  • Dead code is gone. Every new target is declared and exercised.
  • No silent failure. Ordinary parser errors remain results; panics and property failures remain findings.
  • Comments state what is true now. Findings and commands live in the fuzz README.
  • No relaxed gate. No runtime gate, tolerance or lint was changed.
  • cargo fmt and cargo clippy are clean on the Jinja crate and standalone fuzz crate.

Duplication found or removed: none.

What I ran

  • FAIL-first: the new Unicode tag-closer unit test panicked at find_close before the byte comparison; after the fix, all 23 Jinja unit tests pass.
  • cargo test -p bloomery-serve: 206 unit tests pass; hardware/integration gates marked ignored remain for the maintainer.
  • cargo test --manifest-path fuzz/Cargo.toml: 2 harness unit tests pass.
  • cargo clippy -p bloomery-jinja --all-targets -- -D warnings and the corresponding standalone fuzz command pass; workspace and fuzz formatting checks pass.
  • Six targets ran with seed 20261012, -max_total_time=60 -max_len=4096 -dict=fuzz/parsers.dict. Jinja render and all four tool scanners completed 61-second campaigns without a finding. Jinja parse found the nesting failure below after approximately 43 seconds. Its curated seeds, including the Unicode regression, pass a separate 100-run smoke check.
  • Planted-defect check: in a disposable worktree, replace GLM's buffered append with replacement on every push. cargo fuzz run glmxml fuzz/corpus/glmxml -- -seed=20261012 -runs=100 -max_len=4096 -dict=fuzz/parsers.dict exits 1 with character chunks changed the parse. The defect is absent from this branch.
  • Scoped contributor static units (fmt, arch, comments, levers, loads, ptx-names, rustflags, unsafe, waits): DONE tier=t0 total=9 red=0 wall=17s.
  • cargo metadata --no-deps keeps 25 engine workspace members and excludes bloomery-fuzz.

Known unresolved finding: fuzz/findings/jinja-deep-expression.txt (1630 bytes) exhausts the Jinja parser stack under AddressSanitizer. It is retained outside the routine seed corpus, with a direct command in fuzz/README.md. This PR does not invent a nesting limit or suppress the failure. A maintainer should decide the parser resource contract and follow-up fix.

This is scoped contributor validation, not a claim that all T0/T1 units or the workstation's selected GPU gates ran. The root manifest changes only the workspace exclusion; the Jinja host behavior changes as described. Maintainer verification and the known nesting finding are why this PR is a draft.

Hardware

Linux 7.0.0-38-generic x86_64, Intel Core i5-12600K, approximately 64 GB RAM; pinned nightly-2026-08-28, RUSTFLAGS=-C target-cpu=native. No NVIDIA GPU or model inference was used.

@midagedev

Copy link
Copy Markdown
Owner

Thank you. The 0.3.1 release is being cut now, so I will review this after the tag today.

@midagedev

Copy link
Copy Markdown
Owner

The find_close fix is correct, and its test panics on main. Could you move the fix and its test to their own PR? That part can merge now. Four changes for the fuzz crate:

  1. No recipe or CI step runs fuzz/, so its two #[test]s run nowhere (AGENTS.md, "Tests are the gates"). Add a lab-fuzz recipe in the lab-engram shape (lab- is not selected by just affected): cargo test --manifest-path fuzz/Cargo.toml, then each target for 60 s.
  2. Move the jinja_parse stack overflow to an issue with its input, and drop fuzz/findings/ and the README section "Observed parser limit". A release build aborts at 2037 nested parentheses (aarch64 Mac, 8 MB stack).
  3. Regenerate fuzz/Cargo.lock on current main. It pins bloomery-serve 0.3.0; main is 0.3.1.
  4. The planted-defect run covers GLM only (issue fuzz: 신뢰할 수 없는 텍스트를 읽는 파서에 cargo-fuzz 타깃 추가 #8). Add one for jinja_render, or say why the shared scan and the seeds are enough for the others.
    "Duplication: none" misses hw_*_parse_does_not_depend_on_chunking in crates/serve/tests/{glmxml,qwenxml,hermes,dsml}.rs; they pin the same property. Name them in the README.

@midagedev

Copy link
Copy Markdown
Owner

Update: you do not need to change anything. We will make these changes on your branch ourselves and then merge it:

  • the find_close fix stays in this PR;
  • the fuzz items above;
  • a depth limit in the jinja parser, which closes the stack overflow you found.
    Thank you for the fuzz work. It found a real crash.

@midagedev
midagedev merged commit e70db1e into midagedev:main Oct 12, 2026
midagedev added a commit that referenced this pull request Oct 12, 2026
@juliankang4 juliankang4 added documentation Improvements or additions to documentation model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fuzz: 신뢰할 수 없는 텍스트를 읽는 파서에 cargo-fuzz 타깃 추가

3 participants