Commit 6f18caf
fix(assail): strip comments before counting unsafe/FFI patterns
The Rust and Zig analysers previously substring-matched dangerous-pattern
keywords (`unsafe {`, `unsafe fn`, `@cImport`, `@ptrCast`, `@intToPtr`,
`@ptrToInt`) directly against the raw source text. This fired false
positives against files whose only mentions of those patterns were inside
comments — typically meta-tests documenting a no-unsafe contract or
architectural headers describing what the file does.
Two motivating cases from 007:
- `crates/oo7-core/tests/aspect_tests.rs` — a meta-test whose stated
purpose is literally "the absence of `unsafe` in this file IS the
assertion" was flagged as containing 1 unsafe block because seven
comments discussed the word "unsafe".
- `compiler-core/build.zig` — a Zig build script flagged as "2 C interop
imports" because two comment lines (file header + section divider)
described the file's role using the string `@cImport`, even though the
file contained zero real invocations.
Fix:
- Rust analyser: after the existing `strip_string_literals_rs` pass, run
`strip_proof_comments(_, "//", Some(("/*", "*/")))` to also remove
line + block comments before the match counting. String literals go
first so that `//` or `/*` embedded in a string doesn't get treated
as a comment start.
- Zig analyser: introduce a shared `strip_simple_double_quoted_strings`
helper (handles C-style `"..."` with `\` escapes — simpler than Rust's
raw-string / byte-string / char-literal variants) and use it before
`strip_proof_comments(_, "//", None)` (Zig has no block comments).
Apply to the `@cImport`, `@ptrCast`, `@intToPtr`, `@ptrToInt` counts.
The `count_unsafe_in_test_blocks` and test-only-helper detection paths
still walk raw content — changing them would require threading the
stripped content into line-walking state-machines and would not fix any
observable false-positive (both paths feed into a subtraction that
cancels out in the canonical cases).
Verified: post-fix scan on 007-lang clears both false positives while
preserving every legitimate UnsafeCode / UnsafeFFI finding in
zig_bridge.rs and jit_compiler.rs.
Classification register updated in 007-lang audit doc
(audits/audit-ffi-unsafe.md).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent a22367d commit 6f18caf
1 file changed
Lines changed: 71 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
516 | 516 | | |
517 | 517 | | |
518 | 518 | | |
519 | | - | |
| 519 | + | |
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
| |||
781 | 781 | | |
782 | 782 | | |
783 | 783 | | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
790 | 799 | | |
791 | 800 | | |
792 | 801 | | |
| |||
3296 | 3305 | | |
3297 | 3306 | | |
3298 | 3307 | | |
| 3308 | + | |
| 3309 | + | |
| 3310 | + | |
| 3311 | + | |
| 3312 | + | |
| 3313 | + | |
| 3314 | + | |
| 3315 | + | |
| 3316 | + | |
| 3317 | + | |
| 3318 | + | |
| 3319 | + | |
| 3320 | + | |
| 3321 | + | |
3299 | 3322 | | |
3300 | | - | |
3301 | | - | |
3302 | | - | |
| 3323 | + | |
| 3324 | + | |
| 3325 | + | |
3303 | 3326 | | |
3304 | 3327 | | |
3305 | 3328 | | |
| |||
3318 | 3341 | | |
3319 | 3342 | | |
3320 | 3343 | | |
3321 | | - | |
| 3344 | + | |
3322 | 3345 | | |
3323 | 3346 | | |
3324 | 3347 | | |
| |||
4874 | 4897 | | |
4875 | 4898 | | |
4876 | 4899 | | |
| 4900 | + | |
| 4901 | + | |
| 4902 | + | |
| 4903 | + | |
| 4904 | + | |
| 4905 | + | |
| 4906 | + | |
| 4907 | + | |
| 4908 | + | |
| 4909 | + | |
| 4910 | + | |
| 4911 | + | |
| 4912 | + | |
| 4913 | + | |
| 4914 | + | |
| 4915 | + | |
| 4916 | + | |
| 4917 | + | |
| 4918 | + | |
| 4919 | + | |
| 4920 | + | |
| 4921 | + | |
| 4922 | + | |
| 4923 | + | |
| 4924 | + | |
| 4925 | + | |
| 4926 | + | |
| 4927 | + | |
| 4928 | + | |
| 4929 | + | |
| 4930 | + | |
| 4931 | + | |
| 4932 | + | |
| 4933 | + | |
| 4934 | + | |
| 4935 | + | |
| 4936 | + | |
4877 | 4937 | | |
4878 | 4938 | | |
4879 | 4939 | | |
| |||
0 commit comments