Repository navigation
fix(rust): a test-written expected file cannot pin the owner return (#8097) - #8366
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 4 minutes. View limit details
Comment |
…itten-file refusal (#8097)
EffortlessSteven
left a comment
There was a problem hiding this comment.
REVIEW_READY at 8c2f35b (self-review, COMMENT).
History: 81aca67 was REPAIR_REQUIRED for let-bound escapes (first-match binding abort, incomplete wrapper reduction, fail-open renamed-import handling, no let-bound evidence). The repair scans every binding statement, reduces wrappers and method chains to their root identifier, follows identifier hops, fails closed on missing file facts like the neighbouring golden guard, and is pinned by the new rust_test_written_expected_file_bound fixture plus unit test a_test_written_expected_file_lends_no_weight_pin (discriminating against the pre-repair code). A delta review then caught a field-assignment false binding (holder.want), fixed with a dot-boundary check and a unit control; the final delta review confirms both, with the full owner_pin module green.
Local proof on this head: owner_pin tests pass (243 in-module run, plus the new regression test), all three fixtures pass, check-evidence-promotion-honesty passes (318 cases), check-traceability passes, check-fast passes (14 gates, 32 files), Clippy clean. The repro crate moves exposed -> weakly_exposed while the committed-golden control stays exposed, and its cargo test passes throughout (the mutant survives, which is the point). Static evidence only; no dynamic mutation claim.
Known residuals (non-blocking, noted in the PR body): a writer in a helper outside the test body, and the generic reveal.rs strong-oracle path when observation is confirmed independently.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- Lane ub-worker-handoff is a no-op for PR #8366: the diff is a Rust static-classifier change in ripr that adds expected_reads_written_file and three new fixtures; there are no JavaScript, Worker, postMessage, transferable, SharedArrayBuffer, Atomics, WeakRef/FinalizationRegistry, GC, or detach surfaces in the changed code path, so no worker-handoff or async-capture UB claim applies.
- Test body splits statements by ';' after mask_comments_and_strings; a writer/read on a single physical line with two statements (e.g.
let _ = fs::write(...); let want = fs::read_to_string(...)) is fine, but a macro-expanded writer likewriteln!(f, ...)or a helperwrite_golden(&render(4))invoked inside the test body but defined elsewhere is not visible to test_may_write_files — same inherent limitation the PR body already calls out as Known residual. Not a regression; just noting for the next pass. - Helper-writer invisibility is a known and documented residual (PR body 'Known residuals'). The bound fixture pins
wantfrom the test body, so a writer inside a non-test helper would not be visible to expected_reads_written_file; same limitation as the existing golden guard.
Verification questions
- Confirm author claims 'mutant-survival control cargo test passes throughout' but only the write-then-read fixture is reported; bound variant is implicitly covered by the unit test, not a separate cargo run.
Parked follow-ups
statementsis built viamask.split(';'), so a multi-statement binding collapsed onto one source line (e.g.let a = ..; let b = ..;on one physical line) still parses correctly; nestedfor/ifheaders without trailing;are dropped, but field bindings and plain identifier RHS are handled by binding_rhs.- Helper-bodied writers remain untracked; behaviour matches existing golden-file guard limitation per PR body. Park rather than broaden.
- PR adds a new sibling expected-side refusal but does not extend ast-grep/cargo-audit/cargo-deny disabled-by-config coverage; the new function is documented as fail-closed when file facts are missing (same limitation as the existing golden guard), which is acceptable for #8097 but should be tracked for follow-up.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
EffortlessSteven
left a comment
There was a problem hiding this comment.
REVIEW_READY at 708add3 (self-review, COMMENT).
Delta since 8c2f35b is golden-only: eight fixtures whose expected/human.txt were already stale on main (their branches predated the #8165 plain-language merge and were never re-blessed). An independent delta review verified all 68 changed lines are only the landed #8165 formatting forms, with zero check.json/human-full.txt changes, so classifications, counts, and oracle evidence are untouched. This refresh is why the first qualification's Golden output contracts step failed; it is disclosed here and in the PR body rather than hidden in the fix.
The semantic REVIEW_READY on 8c2f35b carries: no production, test, corpus, or schema output changed in this delta.
There was a problem hiding this comment.
Confirmed findings
- Residual architecture concern: the trace of tests/may_write inference is not surfaced in the admit path; reuse of test_may_write_files is correct but the four-hop frontier + wrapper reduction stack should ideally be wrapped in a small helper (
follow_identifiers_to_file_read) so the existing and new refusals share one traversal. Not blocking; documented limitation. - PR body and Known residuals already disclose the helper-writer invisibility and the reveal.rs generic strong-oracle path that never takes the pin; from a security lens this is the only attack-relevant residual, and it is bounded to the static classifier, not to runtime execution. No new risk introduced.
- Helper-writer invisibility: a writer hidden in a helper function outside the test body is not visible to test_may_write_files / expected_reads_written_file; PR Known residuals already documents this limitation as shared with the existing golden-file guard.
Verification questions
- Confirm four-hop identifier frontier with visited set prevents exponential explosion across long test bodies; combined with mask_comments_and_strings + ';' split before any let/reassignment, the worst case stays linear in statements × hops × wrapper reductions.
- Confirm renamed fs/env file-scope import taint is applied with may_write OR renamed_fs_import — i.e. a renamed
use fs as f;import taints any file read in the body even if no writer exists in the test body, matching the existing golden guard. This is a deliberate fail-closed stance and is consistent across the change, but it means a renamed import alone can downgrade a committed golden read in tests likeuse fs as f; assert_eq!(owner, f::read_to_string(...).unwrap())with no writer. Verify the existing golden guard already does this and the new rule is genuinely consistent.
Refuted
- A file-read expected operand in a let-bound could alias an ArrayBuffer view across ';' splits and cause stale active-view length; refuted because: The expected operand and read target here are Rust &str/String parsed by file_renames_fs_or_env_import into a plain identifier; no JS/WASM/ArrayBuffer/TypedArray surface exists in the diff or seeded thread, so the aliasing concern is out of scope for ub-active-view.
- The new String::collect() of identifier roots inside expected_reads_written_file could drop a borrowed &str and yield a use-after-free at subsequent frontier iterations.; refuted because: The closure only produces owned String values (root, reduced, frontier entries) and never stores a borrow of masked beyond the loop scope; visited/next own their strings. No raw lifetime escapes the function.
- Worker/postMessage/transferable/SharedArrayBuffer/Atomics/WeakRef/FinalizationRegistry/GC/detach UB could be triggered by this PR's changes; refuted because: Diff is source-ub, primary language Rust, all changed code is in crates/ripr/src/analysis/classify/owner_pin.rs (a Rust static classifier). No JS/TS/Worker surfaces in changed or context lines; fixtures are Rust Cargo crates. Test body parsing uses mask_comments_and_strings on Rust source, not JS.
- The bound fixture duplicates logic with the non-bound fixture, creating redundant corpus surface.; refuted because: Fixtures differ on whether the read is inline vs. let-bound (annotated), exercising two distinct code paths in the new traversal (inline
reads_file(expected)branch vs. identifier-hop branch); the dedicated fixture is the minimal unit of discrimination, not duplication.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
Parked follow-ups
- Helper-writer invisibility is the same limitation the PR body documents as a known residual; the unit test deliberately binds the file read inside the test body, which is exactly the scope
expected_reads_written_filecovers. - Helper-writer escape is a parked follow-up, not a missed sibling path: PR body's Known residuals already disclose the limitation and bound the scope to test-body writers, matching the existing golden-file guard.
…-expected # Conflicts: # fixtures/one_hop_field_projection/expected/CHANGELOG.md # fixtures/one_hop_field_projection_discarded/expected/CHANGELOG.md # fixtures/one_hop_field_projection_sibling/expected/CHANGELOG.md # fixtures/one_hop_field_projection_wrong_sink/expected/CHANGELOG.md # fixtures/rust_map_insert_count_empty/expected/CHANGELOG.md # fixtures/rust_map_overwrite_count/expected/CHANGELOG.md # fixtures/seeded_push_after_early_return/expected/CHANGELOG.md # fixtures/typescript_mock_payload_iife_impl/expected/CHANGELOG.md
There was a problem hiding this comment.
Refuted
- Reduction passes in expected_reads_written_file could trim past the boundary and produce a slice referencing the original masked String after mutation of intermediate locals, yielding a UAF.; refuted because: All intermediate text values are owned String produced by to_string()/collect(); no &str escapes or aliases after mutation. reduce uses local
mut text: &strrebinding from the same owned source each loop, never holding a slice across a reallocation. - Hypothetical ResizableArrayBuffer / TypedArray transfer / detach stale-active-view UB could apply to the new expected_reads_written_file traversal in owner_pin.rs.; refuted because: The diff is purely Rust static analysis on .rs source text with borrowed &str slices and a fixed-iteration frontier; there are no ArrayBuffer/TypedArray/SharedArrayBuffer/transfer/detach/Atomics/WeakRef/FinalizationRegistry/GC surfaces in the changed code path, and the seed PR body plus prior lane commentary explicitly mark active-view/worker-handoff as not applicable.
- No JS/Worker/async/GC/detach/transferable surfaces touched; change is a pure Rust static classifier addition.
- The new expected_reads_written_file analysis reads a file via fs::read_to_string at the AST level and could leak across a worker boundary; refuted because: Function operates on already-masked test source strings; no I/O, no worker boundary, no transferable involved. Rust-only static analysis; even if it were wrong it would be a classification bug, not a worker-handoff UB.
- Box::from(slice) / allocation-failure on attacker-controlled expected operand could turn pin refusal into a panic in expected_reads_written_file; refuted because: Not raised by this diff; reducer and mask_comments_and_strings operate on borrowed &str without allocating; no Box::from(slice) or related pattern introduced. False premise.
Parked follow-ups
- Helper-writer outside the test body is invisible to expected_reads_written_file; PR body Known residuals documents it as shared with the existing golden-file guard.
- Generic strong-oracle path in reveal.rs can still credit a file-read expected value when observation is confirmed by an unrelated observer; the pin path never takes this code and is a separate follow-up shape. PR body discloses it.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
- ripr sensor failed (exit Some(2)); fixtures claim to pass locally, so the failure likely reflects local-witness unavailability rather than a classifier regression; not a sibling-path concern.
|
Qualification attribution for 16746ab: Ripr Rust Small Result failed only at Golden output contracts. Hosted drift is 35 human.txt formatting_only entries, each adding one line: "No test stub here: the change shows up as a side effect or call, which needs an observer or mock ripr cannot write". That line is the intended output of merged #8412 (stub route or refusal for every probe family); the fixtures were not re-blessed in that PR. None of the 35 drifted fixtures belongs to this PR, and none of this PR's three fixtures drifts. Upstream PR #8418 ("test(fixtures): bless 35 human goldens for the all-families stub route line (#8412)") owns exactly this re-bless and is in flight, so this PR will not duplicate it. Next step: after #8418 merges, merge main into this branch and re-request qualification. All other hosted steps passed, including the full test suite (16763 tests) and this PR's unit test. |
|
REVIEW_READY for 258bc56 (integrated head). What changed since the 8c2f35b REVIEW_READY: no product-code change. The 35 stale human goldens left by merged #8412 were blessed upstream by merged PR #8418 (d91a25d), which is now integrated here; 258bc56 merges current origin/main with no conflicts. Claim delta vs main remains the bounded #8097 fix: owner_pin.rs + tests, three honesty-corpus fixtures (two weakly_exposed witnesses, one committed-golden exposed control), corpus registration, spec slice, traceability. Combined-tree local proof on 258bc56: a_test_written_expected_file_lends_no_weight_pin 1 passed; check-evidence-promotion-honesty pass. Hosted Ripr Rust Small Result on this head is the arbiter (local Windows goldens may show the platform-only ts_repair_packet entries filed as #8437). Residuals stay disclosed and non-blocking: helper-outside-body writer invisible; generic reveal.rs strong-oracle path; spaced field form; block bare-reassignment traced without a dedicated pin. Demotion remains exposed to weakly_exposed only, never inverted. |
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- Helper-outside-body writer invisibility (a writer in fn write_golden(&str) called from the test body is not visible to test_may_write_files / expected_reads_written_file). Bounded: shared with the existing golden-file guard, disclosed in PR body Known residuals, and limited to static classification — no runtime execution.
Verification questions
- Confirm inline let-bound reduction: wrapper chain (&want, .as_str(), .clone(), .parse().unwrap()) is followed via reduce + 4-hop frontier with visited set; field-assignment holder.want=false-binding control is covered by unit test.
Refuted
- Hypothetical ResizableArrayBuffer / TypedArray transfer / detach stale-active-view UB could apply to the new expected_reads_written_file traversal in owner_pin.rs.; refuted because: Diff is pure Rust static analysis on .rs source text with borrowed &str slices and a fixed-iteration frontier; no ArrayBuffer/TypedArray/SharedArrayBuffer/transfer/detach/Atomics/WeakRef/FinalizationRegistry/GC surfaces in the changed path. PR body and prior lane commentary explicitly mark active-view/worker-handoff as not applicable.
- Self-written golden lets the test rewrite the owner return and pin as exposed, masking a real test gap (CWE-1281 / static-evidence integrity).; refuted because: Refuted by the new refusal: expected_reads_written_file returns true when expected reads a file the test may write, and admits returns false, demoting exposed to weakly_exposed. Committed-golden positive control (rust_committed_golden_expected_file) confirms the inverse (exposed) is preserved when may_write is false. Corpus must-not-promote entry pins the behavior.
Parked follow-ups
- Helper-outside-body writer invisibility is a documented non-memory-lifetime limitation, not a regression; bounded static-classifier risk.
- expected_reads_written_file only matches read_to_string, fs::read, read_to_end, File::open; env::var readers and include_str! macros are out of scope per PR body but are an obvious sibling on the same expected-operand path that reuses file_renames_fs_or_env_import.
- Owner-pin admits the new refusal only inside the OwnerReturnPin::admits path; equivalent expected-side guards in OwnerReturnPin::admits_for_assertion_against_owner (if it exists as a sibling function) and reveal.rs generic strong-oracle path are documented in the PR body as separate follow-up shapes and are not part of #8097 scope.
- Generic strong-oracle path in reveal.rs can still credit a file-read expected value when observation is confirmed by an unrelated observer; that path never takes the pin and is a separate follow-up shape, not a regression of this PR.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
What this does
Fixes #8097. A test that writes its own expected file before comparing could pin the owner return:
std::fs::write("tests/w.txt", render(4))followed byassert_eq!(render(4), fs::read_to_string("tests/w.txt")...)readexposed, although every mutant ofrendersurvives because the test rewrites the golden from the owner before comparing.Change:
OwnerReturnPin::admitsincrates/ripr/src/analysis/classify/owner_pin.rsnow refuses the pin when the expected operand's value comes from reading a file the same test may write. The read may be inline or through plain bindings (a few identifier hops, trivial wrappers); writer detection reuses the fail-closedtest_may_write_files, and a file-scope renamedstd::fs/std::envimport taints too, matching the existing golden-file guard. A committed golden the test never writes still pins.Reproduced first on current main: the repro crate's
cargo testpasses (the mutant survives) while ripr readexposed; after the fix it readsweakly_exposed, and the committed-golden control staysexposed.Verification
| Check | Result |
| --- | --- |
| Repro crate (write-then-read) before/after |
exposed->weakly_exposed; mutant-survival controlcargo testpasses throughout || Positive control (committed golden, no write) | stays
exposed||
cargo test -p ripr --lib -- owner_pin| 243 passed || Fixtures
rust_test_written_expected_file/rust_committed_golden_expected_file| pass; classificationsweakly_exposed/exposedon the return-value probe ||
cargo xtask check-evidence-promotion-honesty| pass (318 cases, including the new must-not-promote / must-promote entries) ||
cargo xtask check-traceability,check-faston the committed candidate | pass (14 gates, 23 files) ||
cargo clippy -p ripr --lib| clean || Hosted CI | merge gate on this head; local full matrix not duplicated |
Review map
expected_reads_written_fileincrates/ripr/src/analysis/classify/owner_pin.rs: the new refusal, placed with the other expected-side refusals inadmits.fixtures/rust_test_written_expected_fileandfixtures/rust_committed_golden_expected_file: the discriminating pair (SPEC, input, diff, blessed expected outputs).fixtures/evidence-promotion-honesty-corpus/corpus.json: the graduated must-not-promote / must-promote cases..allow/spec-system/slices/ripr.slice.test-written-expected-file.v1.tomland.ripr/traceability.toml: the claim and its evidence links.Golden refresh at 708add3
The first hosted qualification failed only in Golden output contracts: eight fixtures (one_hop_field_projection family, rust_map_insert_count_empty, rust_map_overwrite_count, seeded_push_after_early_return, typescript_mock_payload_iife_impl) carried pre-#8165 expected/human.txt bytes already stale on main. They are re-blessed here with the RIPR-SPEC-0122 reason; an independent review verified only formatting lines changed and no classification, count, or oracle content moved.
Known residuals
A writer hidden in a helper function outside the test body is not visible to this check (same limitation as the existing golden-file guard).
The generic strong-oracle path in
reveal.rscan still credit a file-read expected value when observation is confirmed by an unrelated observer; that path never takes the pin and is a separate follow-up shape.Static evidence only; nothing here claims dynamic mutation outcomes.
Rollback: revert the squash merge; fixtures, corpus cases, and goldens revert with it.
Head: 708add3