You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(assail): broaden #[cfg(test)] mod strip; recognise .take() as read bound
Two changes, both narrowing false-positive surface across the estate:
1. strip_cfg_test_modules_rs now applies BEFORE every code_only
substring check in analyze_rust, not just UnboundedAllocation.
The same FP class (`#[test] fn exercises_unsafe_wrapper()` inside
a production file's `#[cfg(test)] mod tests { … }` block counting
toward that file's unsafe-block total) was latent for unsafe /
panic / unwrap / crypto counts — widening the strip closes it.
Measured impact on 007-lang scan:
UnboundedAllocation: 72 → 4 → 0
PanicPath: 21 → 4 (test-mod unwraps excluded)
UncheckedError: 15 → 15 (unchanged — not test-mod)
UnsafeCode: 4 → 4 (unchanged — all FFI boundary)
InsecureProtocol: 1 → 1 (unchanged)
This supersedes the narrow 9eda513 scoping, which used a separate
code_no_test_mods local for the unbounded-allocation check only.
The pipeline is now:
raw content
→ strip_string_literals_rs (string bodies → ' ')
→ strip_proof_comments (// + /* */ → whitespace)
→ strip_cfg_test_modules_rs (#[cfg(test)] mod bodies → whitespace)
= code_only (used by every dangerous-pattern check)
2. has_unbounded_allocations now treats `.take(` as a bounded-read
marker. `.take(N).read_to_end(&mut buf)` and
`.take(N).read_to_string(&mut buf)` are the canonical idioms for
bounding a full-file read in Rust; they should disarm the
UnboundedAllocation rule exactly as the lexical `limit` token
already does.
Previously, a file that bounded its reads idiomatically but did
not happen to contain the lowercase word "limit" anywhere in its
source would still be flagged. The new predicate is:
let read_is_bounded =
code_only.contains("limit") || code_only.contains(".take(");
applied to both read_to_end and read_to_string. Code that relies
on `.take()` semantically (which is the idiom std::io teaches) is
now correctly recognised as bounded.
Tests: 4 new end-to-end tests (186 total; 182 prior + 4 new):
- analyze_rust_ignores_unsafe_inside_cfg_test_mod
- analyze_rust_ignores_unbounded_keyword_in_cfg_test_mod
- analyze_rust_take_disarms_read_to_string
- analyze_rust_read_to_string_without_bound_still_fires (sanity)
All lib tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments