feat(fuzz): add semantic property invariants to all fuzz targets + global stdout cap#159
Closed
feat(fuzz): add semantic property invariants to all fuzz targets + global stdout cap#159
Conversation
Wrap the runner's stdout writer with a limitWriter at the start of each Run() call. Bytes beyond maxStdoutBytes (10 MiB) are silently discarded so that Write() never returns an error and script execution continues normally. This prevents unbounded memory growth from runaway loops or commands that produce excessive output. Also adds TestGlobalStdoutCapSilentlyDrops to verify the cap fires and does not truncate output below the limit. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add four invariants to every non-differential fuzz target: 1. Output bounded: assert stdout <= 10 MiB (exercises the new global cap and acts as a redundant safety net). 2. Determinism: run each script twice with identical filesystem state and assert byte-identical stdout and exit code. 3. Exit code validity: assert only 0, 1, (or 2 for commands that use it) are ever returned. 4. No panic: document that reaching the end of the fuzz body proves no panic escaped Runner.Run(). Invariant 2 is skipped for ss, ps, ip addr/link (live kernel state) and differential fuzz targets (bash comparison, not rshell vs rshell). ip route fuzz targets hold the procNetRouteMu mutex for both runs, ensuring the mocked /proc/net/route content is identical. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
9f86753 to
48322a2
Compare
Collaborator
Author
|
Splitting into two separate PRs. The global stdout cap is in #161. The fuzz invariant changes are being dropped. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two safety enhancements to make RULES.md invariants machine-checked:
interp/api.go,interp/runner_expand.go): wraps the runner's stdout with alimitWriterso no script run can emit more than 10 MiB of output total, regardless of what builtins do individually. Complementary to the existing per-variable (1 MiB) and per-cmdsubst (1 MiB) caps.builtins/tests/andinterp/tests/): each fuzz target now asserts:len(stdout) <= 10 MiBss,ps,ip addr/link)api.gomeans reaching the assertion means no panic occurredTest plan
go test ./interp/... ./builtins/...passesgo test ./builtins/tests/head/ -run FuzzHeadgo test ./interp/tests/ -run TestGlobalStdoutCap🤖 Generated with Claude Code