buffer_format_fuzz: reject a negative --budget #1623

Open
github-bot wants to merge 1 commit from github-bot/gh-1623 into main AGit
Owner

@⁠xel1uz on GitHub · 2026-11-25 06:11 UTC · original
xel1uz:fix/buffer-arg-guards → main · +121 −1 · 2 files · 1 commits · open

Item ID: BUFFER-BUDGET-NEGATIVE (new item; the coordination issue #14 is at GitHub's 2,500-comment cap, so the claim lives here)

Claimed as: BUFFER-BUDGET-NEGATIVE - a negative --budget is silently the run of 0, and --self-test ignores the value entirely. Reproduced on 42537e7b.

What and why

--budget went straight into range(budget), so -1, -100 and -1000000 produced exactly the run of 0 (1026 instead of 1106 elements for 8_8_8_8_UNORM) while every format still printed ok; --self-test builds its patterns with a hardcoded 2 and so ignores the option completely, making --budget -100 and --budget 1000000 identical in the same 1.4 s. A negative value is now ap.error("--budget cannot be negative") (exit 2, usage line), checked before --self-test and before the oracle opens, so it also wins over the exit-77 'hardware oracle unavailable'. 0 stays legal (sweeps only) and the help says so.

Found but left alone to keep this focused: --budget never reaches run_stores, so --mode store --budget N is a silent no-op.

Tested

  • New tests/test_buffer_format_fuzz.py (7 tests, CPU only, hw oracle stubbed): against the tool at 42537e7b 3 failed, 4 passed; with this branch 7 passed, and the 15 buffer-format tests together pass.

  • CLI: --self-test --budget -1 exits 2 with the message (was self-test: ok), --self-test --budget 0 still exits 0.

  • git diff --check clean; python3 -I scripts/check_no_game_data.py clean on the changed files.

GPUs tested: n/a - CPU only, no Vulkan device involved.

AI-assisted: Yes.

Checklist

  • Based on current main (42537e7b) and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption; synthetic inputs only.
  • A new translator rule in the contract table of docs/design.md - not applicable, no translator change.
**@⁠xel1uz** on GitHub · 2026-11-25 06:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1623) `xel1uz:fix/buffer-arg-guards` → `main` · +121 −1 · 2 files · 1 commits · open Item ID: `BUFFER-BUDGET-NEGATIVE` (new item; the coordination issue #14 is at GitHub's 2,500-comment cap, so the claim lives here) Claimed as: `BUFFER-BUDGET-NEGATIVE` - a negative `--budget` is silently the run of `0`, and `--self-test` ignores the value entirely. Reproduced on 42537e7b. ### What and why `--budget` went straight into `range(budget)`, so `-1`, `-100` and `-1000000` produced exactly the run of `0` (1026 instead of 1106 elements for `8_8_8_8_UNORM`) while every format still printed `ok`; `--self-test` builds its patterns with a hardcoded 2 and so ignores the option completely, making `--budget -100` and `--budget 1000000` identical in the same 1.4 s. A negative value is now `ap.error("--budget cannot be negative")` (exit 2, usage line), checked before `--self-test` and before the oracle opens, so it also wins over the exit-77 'hardware oracle unavailable'. `0` stays legal (sweeps only) and the help says so. Found but left alone to keep this focused: `--budget` never reaches `run_stores`, so `--mode store --budget N` is a silent no-op. ### Tested - New `tests/test_buffer_format_fuzz.py` (7 tests, CPU only, hw oracle stubbed): against the tool at 42537e7b **3 failed, 4 passed**; with this branch **7 passed**, and the 15 buffer-format tests together pass. - CLI: `--self-test --budget -1` exits 2 with the message (was `self-test: ok`), `--self-test --budget 0` still exits 0. - `git diff --check` clean; `python3 -I scripts/check_no_game_data.py` clean on the changed files. GPUs tested: n/a - CPU only, no Vulkan device involved. AI-assisted: Yes. ### Checklist - [x] Based on current `main` (42537e7b) and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption; synthetic inputs only. - [ ] A new translator rule in the contract table of `docs/design.md` - not applicable, no translator change.
--budget is a count of random elements per format, and a negative one was
accepted with exit 0 and no message. `for _ in range(budget)` simply does not
run, so -1, -100 and -1000000 produced exactly the run of 0 -- 1026 instead of
1106 elements for 8_8_8_8_UNORM -- and every format still reported "ok".
--self-test was worse: it builds its own patterns with a hardcoded budget of 2
and never reads the option, so `--self-test --budget -100` and `--budget
1000000` both printed the same "self-test: ok" in the same 1.4 s.

Before:
  $ python -I tools/buffer_format_fuzz.py --self-test --budget -1
  self-test: ok                                # exit 0
  $ python -I tools/buffer_format_fuzz.py --oracle hw --budget -3
  hardware oracle unavailable: ...             # exit 77, no GPU needed to know

After, one check next to the other argument guards and before both the
self-test and the oracle, so the value is validated even where it is not used:

  $ python -I tools/buffer_format_fuzz.py --self-test --budget -1
  buffer_format_fuzz.py: error: --budget cannot be negative   # exit 2
  $ python -I tools/buffer_format_fuzz.py --self-test --budget 0
  self-test: ok                                # 0 stays legal: sweeps only

tests/test_buffer_format_fuzz.py (CPU only, hw_oracle stubbed) covers the
negative value on both paths, that it is refused before the oracle is opened,
that 0 stays legal and that -1 is otherwise indistinguishable from 0.
3 of its 7 tests fail without this change, 7 pass with it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:58:29 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 17:28 UTC · original

Reviewed 0294aed: ran python -I tests/test_buffer_format_fuzz.py - 7/7 pass with the PR; copied onto main, the 3 negative-budget tests fail, so they genuinely pin the fix. A 12-case CLI probe on both trees shows main accepting --budget -1 (exit 0, "self-test: ok") while the PR refuses it with exit 2 before the oracle is opened; budget 0, -0, positive and unrelated options are unchanged. compileall and check_no_game_data.py are clean on the new files. No findings.

AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 17:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1623#issuecomment-7169545993) Reviewed 0294aed: ran `python -I tests/test_buffer_format_fuzz.py` - 7/7 pass with the PR; copied onto main, the 3 negative-budget tests fail, so they genuinely pin the fix. A 12-case CLI probe on both trees shows main accepting `--budget -1` (exit 0, "self-test: ok") while the PR refuses it with exit 2 before the oracle is opened; budget 0, -0, positive and unrelated options are unchanged. compileall and check_no_game_data.py are clean on the new files. No findings. AI-assisted review. **Recommendation:** Merge
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1623/head:github-bot/gh-1623'
git switch 'github-bot/gh-1623'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1623'
git switch 'github-bot/gh-1623'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1623'
git switch 'github-bot/gh-1623'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1623'
git switch 'main'
git merge --squash 'github-bot/gh-1623'
git switch 'main'
git merge --ff-only 'github-bot/gh-1623'
git switch 'main'
git merge 'github-bot/gh-1623'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.