sb-dev/openquant / .agents/skills/rust-review
rust-review
VerifiedReview Rust crates, services, or libraries for safe/unsafe boundary issues, memory safety, concurrency hazards, panic-induced denial of service, FFI safety, and async runtime mistakes. Use for a Rust security audit, especially unsafe, FFI, or concurrent code.
upstream/prompts/general/adversarial-trait-finder.md
View on GitHub---
name: adversarial-trait-finder
description: Detects unsafe code trusting return values from user-supplied trait impls (Read, Iterator, Hash, etc.)
---
**Finding ID Prefix:** `TRAITADV`.
**Bug shape (research):** library accepts `T: Read`, allocates a buffer based on `T::read()`'s reported size, and writes via unchecked unsafe. Hostile `impl Read for HostileType` returns a size larger than the actual buffer → OOB write.
**Gates:**
1. Public generic API with a trait-bounded parameter (`T: Read`, `T: Iterator`, `T: Hasher`, `T: ExactSizeIterator`, custom traits).
2. The implementation feeds the trait method's return value (size, count, index, hash) into an `unsafe` operation or a length-trusting sink — `Vec::set_len`, `get_unchecked`, `ptr::write`/`copy_nonoverlapping` at a computed offset, or `from_raw_parts`. (`Vec::with_capacity`/`reserve` is **not** an OOB-write sink — it only reserves, with `len` still `0`, so a hostile size cannot write out of bounds through it — but an attacker-controlled capacity is a separate allocation/memory-exhaustion DoS; note that distinctly rather than as memory corruption.)
3. No defensive check ensures the reported value matches reality (e.g., `ExactSizeIterator::len()` is a hint, not a guarantee — `unsafe` code must not trust it).
**FPs:**
- Trait is sealed (`pub trait T: sealed::Sealed`).
- The reported value is only used as a heuristic and validated downstream.
**Patch:** treat trait method outputs as untrusted; bound them; never feed directly into `set_len` or `get_unchecked`.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |