Commit 0f6ea94
fix: bound three unbounded file reads (resolves self-scan Critical) (#51)
## Summary
Self-scanning panic-attack with the latest release surfaced a **Critical
UnboundedAllocation** in `attestation/mod.rs::verify_attestation_file` —
and, on closer inspection, two sibling sites the analyzer's per-file
heuristic glossed over. All three were the last residual violations of
the codebase-wide invariant that every file read must be
capacity-bounded.
## Discovery path
Ran the freshly-built release of panic-attack on its own source tree:
```
./target/release/panic-attack assail . --output /tmp/panic-self-scan.json
```
Among the 12 findings, one Critical pointed at `src/attestation/mod.rs`
— the heuristic correctly fired because that file has **zero** other
`.take(...)` calls. The other two sites (`src/assemblyline.rs:120`,
`src/assail/mod.rs:230`) live in files that DO use `.take(...)`
elsewhere, so the analyzer's per-file all-or-nothing classifier flagged
them as bounded overall. Manual triage caught those — separate concern,
doesn't need analyzer changes here.
## Fixes
All three follow the established pattern of every other read in the
codebase (`File::open` + `.take(LIMIT)` + `.read_to_string`).
| Site | Cap | Rationale |
|---|---|---|
| `src/attestation/mod.rs::verify_attestation_file` | 16 MiB | JSON
envelopes embed three hashes plus a small signature; legitimate
envelopes < 1 MiB. |
| `src/assemblyline.rs::load_cache_file` | 256 MiB | Fingerprint caches
grow with estate size; large enough for multi-thousand-repo rollups. |
| `src/assail/mod.rs::load_user_classifications` | 4 MiB | Hand-edited
audit a2ml registries are small. |
## Verification
- [x] `cargo build --bin panic-attack --features signing,http` — clean
- [x] `cargo clippy --all-targets --features signing,http -- -D
warnings` — clean
- [x] `cargo test --bin panic-attack --features signing,http` — 236
passed, 0 failed
- [x] `cargo fmt --check` — clean
- [x] **Self-scan before**: 12 findings (1 Critical UnboundedAllocation)
- [x] **Self-scan after**: 11 findings (Critical resolved; residuals are
intentional — `examples/vulnerable_program.rs` unsafe blocks, test
unwraps, etc.)
- [x] GPG-signed commit
## Out of scope
The analyzer's per-file heuristic for `read_to_string` boundedness is
correct-by-default (files that use `.take(...)` are *probably* bounded
throughout), but the two sites it missed argue for a per-call check.
That's a detector improvement, separate from these data-path fixes;
would file as a follow-up if the team thinks it's worth it.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent ea02d50 commit 0f6ea94
3 files changed
Lines changed: 43 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
228 | 235 | | |
229 | 236 | | |
230 | | - | |
231 | | - | |
232 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
233 | 247 | | |
234 | 248 | | |
235 | 249 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
119 | 124 | | |
120 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
121 | 132 | | |
122 | 133 | | |
123 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
72 | 83 | | |
73 | 84 | | |
74 | 85 | | |
| |||
0 commit comments