fix: align generator contracts - #17
Merged
Merged
Conversation
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.
Description
Align the generator, CLI, and Python bindings around one consistent contract
for determinism, opcode budgeting, and size-limited generation.
This change makes repeated generation calls reset cleanly, derives distinct
deterministic per-sample seeds in batch mode, normalizes and bounds opcode
ranges, treats
max_opcodesas a total emitted-opcode budget, makes persistentID opcodes opt-in, and exposes a real max-size generation path to the Python
API so
PickleMutatorno longer truncates finished pickles into invalid output.Related Issue
Generator range, size, and determinism remediation from Hunter campaign
pickle-fuzzer-patch-test:F-0006,F-0022,F-0023,F-0024,F-0025,F-0034,F-0035,F-0038,F-0046,F-0047,F-0048,F-0077,F-0078,F-0079,F-0080,F-0081,F-0092,F-0095,F-0097Type of Change
Changes Made
generate()andgenerate_from_arbitrary()reset state before each runSTOP, with impossible budgetsrejected instead of silently exceeded
with_buffer_size()becomes a real max-size generation controlPERSID/BINPERSIDare disabled by default and require explicit opt-induplicating the same pickle into every output slot
--mutators bitflip output.pklno longer swallows the output path--allow-persistent-idsflagset_opcode_range()preserves seed and other generator configurationgenerate()andgenerate_from_bytes()acceptmax_sizePickleMutatorso it asks the Rust generator to honormax_sizeup front and falls back to a minimal valid pickle on generation failure when
one fits in the requested budget.
Testing Performed
Describe the tests you ran to verify your changes:
cargo test)Test commands:
cargo fmt uv run python -m py_compile python/pickle_fuzzer/fuzzer.py python/tests/test_generation.py python/tests/test_fuzzer.py uv run maturin develop uv run pytest python/tests cargo test git diff --checkChecklist
Before submitting this PR, please ensure:
cargo fmt)cargo clippy -- -D warnings)cargo test)Performance Impact
If this PR affects performance:
Benchmark results:
Screenshots/Examples
Not applicable.
Additional Notes
The new Python
max_sizepath intentionally prefers returning an error or aminimal valid fallback over truncating a completed pickle stream. That keeps the
structure-aware contract intact for Atheris users instead of silently feeding
raw entropy or chopped bytecode back into the target parser.
Breaking Changes
Generator.generate()andGenerator.generate_from_bytes()in Python nowaccept
max_size, the CLI exposes--allow-persistent-ids, and impossibletotal-opcode budgets now return errors instead of silently exceeding the
declared maximum.