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/general/packed-field-ref-finder.md

View on GitHub
---
name: packed-field-ref-finder
description: Detects undefined behavior from creating references to fields of #[repr(packed)] structs, including implicit borrows via auto-deref
---

**Finding ID Prefix:** `PACKEDREF`.

**Bug shape:** `#[repr(packed)]` / `#[repr(C, packed)]` / `#[repr(packed(N))]` removes inter-field padding, so fields with alignment > 1 can sit at unaligned addresses. Rust requires every `&T` / `&mut T` to be aligned *at creation*, not only on dereference. Taking `&s.field`, `&mut s.field`, `&s.field as *const _`, or any context that implicitly borrows the field (`println!("{}", s.field)`, `&self` method calls on the field, `match &s.field`, indexing a nested array field) is UB when the field is misaligned. Common in C-FFI layout-matched structs and wire formats. Modern rustc rejects these sites as a hard error (`E0793`); the older `unaligned_references` lint was **converted to that hard error** (rust-lang/rust#82523), so `#[allow(unaligned_references)]` no longer suppresses anything — it is a no-op that still emits `E0793`. Macro-generated borrows and pre-error legacy snapshots are where these still surface.

**Verification gates (ALL must pass):**

1. **Packed struct in scope:** a type annotated `#[repr(packed)]`, `#[repr(C, packed)]`, or `#[repr(packed(N))]` (including via type alias or generic instantiation).
2. **Reference or implicit borrow of a field:** explicit `&s.field` / `&mut s.field`; `&s.field as *const _` / `&mut s.field as *mut _` (the `&` still forms an unaligned reference before the cast); or an auto-borrow site — `println!`/`format!`/`write!`/`Debug` of a field (the format machinery borrows **every** argument regardless of `Copy`, so `println!("{}", s.copy_field)` is still `E0793`), passing `s.field` where a reference is expected, or indexing/splitting a nested array field. Only a *braced* `{ s.field }` or a prior by-value copy avoids forming the reference.
3. **Field may be misaligned:** the field type has `align_of > 1` (skip `u8`/`i8`/`bool` and `[u8; N]`). For `#[repr(packed(N))]` with `N > 1`, skip fields whose type alignment is `<= N` only when a `// SAFETY:` comment proves both the struct base address and field offset meet that alignment; otherwise flag for reviewer confirmation.
4. **Not a by-value copy:** the access is not `{ s.field }`, `let v = s.field`, or an assignment/move that copies by value without forming a reference.

**FPs to reject:**

- Direct by-value read/write of a `Copy` field (`let x = s.field; s.field = v;`), including braced copies in macros (`println!("{}", { s.field })`).
- `ptr::addr_of!(s.field)` / `ptr::addr_of_mut!(s.field)` plus `read_unaligned` / `write_unaligned` / `copy_nonoverlapping` — no intermediate `&T` is formed.
- Raw borrow syntax `&raw const s.field` / `&raw mut s.field` (no reference invariants).
- Field type has alignment 1, or the leaf field nested in the packed struct is alignment 1.
- Test-only `#[cfg(test)]` modules.

**Search patterns:**

```
#\[repr\([^\]]*packed
(?:^|[^&\w])&(?:mut\s+)?[\w.]+\.\w+
\b(?:e?print(?:ln)?|format|write(?:ln)?|panic|assert(?:_eq|_ne)?|dbg)!\([^)]*\.\w+
```

For each `repr(packed*` hit, grep the struct name for field-borrow sites and check the gates per site.

**Patch:** read/write `Copy` fields by value; otherwise use `ptr::addr_of!` / `ptr::addr_of_mut!` with `read_unaligned` / `write_unaligned`, preferring `&raw const` / `&raw mut` over `&field as *const _`. If alignment can be restored, drop `packed` or add explicit padding fields.

Distinct from `REPRC` (field reordering from a missing `repr` at an FFI boundary) and `REPRCPAD` (uninitialized padding leaking across FFI), and from `PTRCAST` (pointer provenance / cast-to-wrong-type UB — distinct from forming an unaligned `&T`).
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