Skip to content

sb-dev/openquant / .agents/skills/rust-review

rust-review

Verified

Review 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.

FileKindSize
SKILL.mdskill md5.4 KB
upstream/.claude-plugin/plugin.jsonconfig530 B
upstream/README.mdmarkdown8.2 KB
upstream/agents/rust-review-dedup-judge.mdmarkdown20.4 KB
upstream/agents/rust-review-fp-judge.mdmarkdown23.1 KB
upstream/agents/rust-review-worker.mdmarkdown31.8 KB
upstream/prompts/clusters/async-runtime.mdmarkdown855 B
upstream/prompts/clusters/concurrency-data-race.mdmarkdown2.6 KB
upstream/prompts/clusters/concurrency-locking.mdmarkdown6.9 KB
upstream/prompts/clusters/error-handling.mdmarkdown1.6 KB
upstream/prompts/clusters/ffi-cross-language.mdmarkdown3.3 KB
upstream/prompts/clusters/info-disclosure.mdmarkdown562 B
upstream/prompts/clusters/input-os-safety.mdmarkdown1.1 KB
upstream/prompts/clusters/layout-safety.mdmarkdown572 B
upstream/prompts/clusters/logic-correctness.mdmarkdown3.8 KB
upstream/prompts/clusters/manifest.jsonconfig10.9 KB
upstream/prompts/clusters/memory-safety.mdmarkdown4.6 KB
upstream/prompts/clusters/panic-dos.mdmarkdown6.0 KB
upstream/prompts/clusters/recursion-dos.mdmarkdown5.3 KB
upstream/prompts/clusters/resource-handling.mdmarkdown1.5 KB
upstream/prompts/clusters/static-hygiene.mdmarkdown746 B
upstream/prompts/clusters/unsafe-boundary.mdmarkdown15.6 KB
upstream/prompts/general/abi-mismatch-finder.mdmarkdown705 B
upstream/prompts/general/adversarial-trait-finder.mdmarkdown1.5 KB
upstream/prompts/general/arithmetic-overflow-finder.mdmarkdown2.1 KB
upstream/prompts/general/assertion-reachable-finder.mdmarkdown879 B
upstream/prompts/general/async-blocking-finder.mdmarkdown1.2 KB
upstream/prompts/general/atomic-race-finder.mdmarkdown1.3 KB
upstream/prompts/general/buffer-overflow-unsafe-finder.mdmarkdown2.6 KB
upstream/prompts/general/bufwriter-unflushed-finder.mdmarkdown995 B
upstream/prompts/general/cancel-safety-finder.mdmarkdown1.2 KB
upstream/prompts/general/cargo-lint-config-finder.mdmarkdown2.4 KB
upstream/prompts/general/closure-ffi-finder.mdmarkdown3.9 KB
upstream/prompts/general/closure-panic-finder.mdmarkdown1.1 KB
upstream/prompts/general/collection-key-mutation-finder.mdmarkdown1.9 KB
upstream/prompts/general/cstring-dangling-finder.mdmarkdown1.3 KB
upstream/prompts/general/deprecated-api-finder.mdmarkdown1.9 KB
upstream/prompts/general/destructor-skip-finder.mdmarkdown1.4 KB
upstream/prompts/general/double-free-finder.mdmarkdown1.6 KB
upstream/prompts/general/drop-panic-finder.mdmarkdown973 B
upstream/prompts/general/dyn-trait-ffi-finder.mdmarkdown2.8 KB
upstream/prompts/general/float-edge-finder.mdmarkdown798 B
upstream/prompts/general/foreign-drop-finder.mdmarkdown2.7 KB
upstream/prompts/general/invalid-free-finder.mdmarkdown1.2 KB
upstream/prompts/general/lossy-from-into-finder.mdmarkdown603 B
upstream/prompts/general/lossy-str-conversion-finder.mdmarkdown1.2 KB
upstream/prompts/general/msrv-mismatch-finder.mdmarkdown401 B
upstream/prompts/general/nondeterminism-finder.mdmarkdown1.6 KB
upstream/prompts/general/opaque-pointer-finder.mdmarkdown1.9 KB
upstream/prompts/general/ord-eq-hash-finder.mdmarkdown754 B
upstream/prompts/general/out-of-bounds-index-finder.mdmarkdown727 B
upstream/prompts/general/packed-field-ref-finder.mdmarkdown3.7 KB
upstream/prompts/general/panic-unwind-unsafe-finder.mdmarkdown3.0 KB
upstream/prompts/general/path-traversal-join-finder.mdmarkdown1.7 KB
upstream/prompts/general/pointer-exposure-finder.mdmarkdown1.8 KB
upstream/prompts/general/raw-fd-lifecycle-finder.mdmarkdown2.0 KB
upstream/prompts/general/recursive-deserialize-stack-overflow-finder.mdmarkdown4.8 KB
upstream/prompts/general/recursive-drop-stack-overflow-finder.mdmarkdown2.7 KB
upstream/prompts/general/recursive-format-stack-overflow-finder.mdmarkdown4.1 KB
upstream/prompts/general/refcell-borrow-panic-finder.mdmarkdown1.2 KB
upstream/prompts/general/repr-c-padding-finder.mdmarkdown2.2 KB
upstream/prompts/general/resource-exhaustion-finder.mdmarkdown2.4 KB
upstream/prompts/general/result-discarded-finder.mdmarkdown1.6 KB
upstream/prompts/general/select-bias-finder.mdmarkdown1.2 KB
upstream/prompts/general/send-sync-bounds-finder.mdmarkdown2.6 KB
upstream/prompts/general/serialize-struct-mismatch-finder.mdmarkdown2.3 KB
upstream/prompts/general/shared-memory-race-finder.mdmarkdown2.8 KB
upstream/prompts/general/static-mut-race-finder.mdmarkdown2.8 KB
upstream/prompts/general/str-slice-boundary-finder.mdmarkdown1.0 KB
upstream/prompts/general/string-comparison-finder.mdmarkdown1.4 KB
upstream/prompts/general/toctou-finder.mdmarkdown1.3 KB
upstream/prompts/general/uninitialized-read-finder.mdmarkdown1.8 KB
upstream/prompts/general/union-ub-finder.mdmarkdown3.5 KB
upstream/prompts/general/unsafe-sync-impl-finder.mdmarkdown3.7 KB
upstream/prompts/general/unwrap-on-untrusted-finder.mdmarkdown1.3 KB
upstream/prompts/general/use-after-free-finder.mdmarkdown2.9 KB
upstream/prompts/general/vec-set-len-uninit-finder.mdmarkdown2.5 KB
upstream/scripts/build_run_plan.pyscript24.0 KB
upstream/scripts/generate_sarif.pyexecutablescript22.9 KB
upstream/scripts/pyproject.tomlmanifest220 B
upstream/scripts/test_gating.pyscript12.6 KB
upstream/scripts/test_generate_sarif.pyscript19.5 KB
upstream/scripts/test_prompt_regexes.pyscript4.3 KB
upstream/scripts/test_split.pyscript10.2 KB
upstream/scripts/test_validate_artifacts.pyscript10.3 KB
upstream/scripts/validate_artifacts.pyscript11.4 KB
upstream/skills/rust-review/SKILL.upstream.mdmarkdown43.5 KB

upstream/prompts/clusters/panic-dos.md

View on GitHub
---
name: cluster-panic-dos
kind: cluster
consolidated: false
covers:
  - resource-exhaustion  # RESEXHAUST
  - unwrap-on-untrusted  # UNWRAP
  - arithmetic-overflow  # ARITHOFL
  - assertion-reachable  # ASSERTREACH
  - out-of-bounds-index  # OOBIDX
  - str-slice-boundary   # STRSLICE
  - refcell-borrow-panic # REFCELLPANIC
---

# Cluster: Panic-induced DoS and availability

Rust panics terminate the thread (or process under `panic = "abort"`). On servers, an attacker-triggered panic is a DoS. **`RESEXHAUST` runs first:** CPU/RAM exhaustion via unbounded loops, O(n²) work, or uncapped `Vec::reserve` often leaves the process alive (no panic) — a distinct availability class from abort-on-panic.

ID prefixes: `RESEXHAUST`, `UNWRAP`, `ARITHOFL`, `ASSERTREACH`, `OOBIDX`, `STRSLICE`, `REFCELLPANIC`.

## Phase A — Profile gate (do this first)

Arithmetic-overflow panics (`a + b`, `a - b`, `a * b`, `-a`, `a << b`) are conditional on `overflow-checks`. Default: `true` in debug, `false` in release. Check the target profile before scoring `ARITHOFL` findings:

```
rg seed: "overflow-checks\s*=" path="**/Cargo.toml"
```

- If `overflow-checks = true` on the relevant profile (often `[profile.release]` in security-sensitive crates — Solana programs, Substrate runtimes, etc.): plain `+ - * << >>` and unary `-` are panic candidates.
- If unset or `false` on release: plain `+ - *` wrap silently and `<< >>` mask the shift amount (mod bit-width) in release builds — **not** a panic-DoS. If the wrapped value is security-relevant (a length / index / capacity / allocation size, an auth or accounting counter, etc.), still file it under `ARITHOFL`, noting it is a *release-silent wrap* (not a panic); the fp+severity judge ranks it. There is **no** arithmetic pass in `logic-correctness`, so do not "route" it elsewhere — filing under `ARITHOFL` with the release-silent note is how a silent-wrap bug reaches the report.

**Unconditional arithmetic panics** (fire regardless of `overflow-checks`, score these always):
- `/` or `%` by zero
- `i::MIN / -1`, `i::MIN % -1`

## Phase B — Resource exhaustion inventory (RESEXHAUST)

```
rg seed: "(Vec|String|BytesMut|VecDeque)::(with_capacity|reserve)\s*\(|\.(reserve|reserve_exact|try_reserve|with_capacity)\s*\("  # assoc-fn `Vec::with_capacity(` + dominant method `buf.reserve(`/`v.reserve_exact(`
rg seed: "\.resize\s*\(|vec!\[[^;]+;\s*\w+\]|repeat\s*\("
rg seed: "unbounded(_channel)?|async_channel::unbounded|crossbeam.*unbounded"
rg seed: "for\s+\w+\s+in\s+0\.\.|while\s+.*\.len\(\)|loop\s*\{"
```

Trace whether capacity/index/count is tainted from decode/parse of external input.

## Phase C — Panic inventory

```
rg seed: "\.unwrap(_err)?\s*\(\s*\)|\.expect\s*\("
rg seed: "(panic!|todo!|unimplemented!|unreachable!|assert(_eq|_ne)?!)\s*\("
rg seed: "\bas\s+(u\d+|i\d+|usize|isize)\b"
rg seed: "\[\s*\w+\s*\]"  # bracket indexing
rg seed: "[\w)\]]\s*[/%]\s*[\w(]"  # division / modulo — unconditional panic on divide-by-zero (matches tight `a/b`, `len%n`, `(x)/y`; over-matches `/` `%` inside strings — FP-triage those)
rg seed: "\[[^\]]*\.\.[^\]]*\]|\.split_at(_mut)?\s*\(|\.truncate\s*\("  # str range-slice / split_at / truncate — char-boundary panic
rg seed: "RefCell|\.borrow_mut\s*\("
rg seed: "\.try_borrow_mut\s*\(\s*\)\s*\.(unwrap(_err)?|expect)\s*\("  # try_borrow_mut().unwrap()/expect() re-introduces the panic
```

**Negative-signal grep (sites already hardened, skip for `ARITHOFL`):**

```
rg seed: "\b(checked|saturating|wrapping|overflowing)_(add|sub|mul|shl|shr|neg|pow)\b"
```

These methods never panic on overflow — they're the explicit non-panicking alternatives. Use this grep to *exclude* hardened sites from the arithmetic inventory, not to find panic candidates. **Do not exclude `div`/`rem` this way:** only `checked_div`/`checked_rem` are divide-by-zero-safe — `wrapping_div`/`saturating_div`/`overflowing_div` (and the `_rem` forms) **still panic on divide-by-zero**, so they stay in the div-by-zero inventory. (One exception to the exclusion: `checked_*().unwrap()` chains re-introduce a panic and should fall out of the `unwrap` grep above.)

## Deconfliction

- `RESEXHAUST` vs `ARITHOFL`: allocation/loop DoS vs integer overflow panic — different mechanics; both may cite the same untrusted `n` but file separately when both apply.
- `RESEXHAUST` vs `RECURSEDES` / `RECURSEFMT` / `RECURSEDROP` (recursion-dos): stack exhaustion from depth, not CPU/RAM amplification in safe loops.
- `RESEXHAUST` vs `TRAITADV`: untrusted length into safe `Vec::reserve` files here; untrusted trait return into `unsafe`/`set_len` files at `TRAITADV` / `SETLEN`.
- `OOBIDX` owns integer-index OOB on `Vec`/`[T]`; `STRSLICE` owns `str` range-slice / `split_at` / `truncate` panics where the byte index lands off a UTF-8 char boundary (a panic that fires even *in bounds*).
- `REFCELLPANIC` owns single-threaded interior-mutability borrow panics; a borrow panic inside `Drop` routes to `DROPPANIC`; cross-thread/callback reentrancy routes to the concurrency-locking reentrancy classes.

## Pass order

Run the seven passes in manifest order, applying the Phase A–C inventories above (detailed detection + FP guidance live in the per-class finder files):

1. **`RESEXHAUST` — resource-exhaustion** (first) — uncapped alloc / O(n²) / unbounded loop on untrusted input; often no panic at all (pure availability). Phase B.
2. **`UNWRAP` — unwrap-on-untrusted** — `unwrap()`/`expect()` on an attacker-controlled `Result`/`Option`. Phase C.
3. **`ARITHOFL` — arithmetic-overflow** — overflow panic on a reachable path, gated by `overflow-checks` (see Phase A). Phase A/C.
4. **`ASSERTREACH` — assertion-reachable** — reachable `assert!` / `unreachable!` / `panic!` / `todo!`. Phase C.
5. **`OOBIDX` — out-of-bounds-index** — integer index past a `Vec`/`[T]` bound on untrusted input. Phase C.
6. **`STRSLICE` — str-slice-boundary** — `str` range-slice / `split_at` / `truncate` landing off a UTF-8 char boundary. Phase C.
7. **`REFCELLPANIC` — refcell-borrow-panic** — reachable `RefCell` double-borrow panic. Phase C.
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: 471kUpdated Claude CodeCodexVerifiedInstall
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: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall