Skip to content

fix(ffi): annotate the audited Zig context-pointer casts for Hypatia - #468

Closed
hyperpolymath wants to merge 5 commits into
mainfrom
claude/new-session-th4e9w-zig-cast-audit
Closed

hyperpolymath wants to merge 5 commits into
mainfrom
claude/new-session-th4e9w-zig-cast-audit

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Summary

governance / Validate Hypatia Baseline is red on main (2ab7574). Hypatia's code_safety/zig_ptr_cast and zig_align_cast rules now flag the nine @ptrCast(@alignCast(raw)) lines in src/zig_ffi/chapel_bridge.zig and src/zig_ffi/runtime_owner.zig as high.

Each of those lines does the same thing: it gets a callback's own *@This() back from the type-erased *anyopaque it was registered with. The pointer comes from runtime_owner.Work.context or, for the allocator test fixture, from a std.mem.Allocator vtable's ptr. So the cast restores the pointer's original type and alignment, and the pattern is sound.

I've fixed it in the code rather than adding a baseline entry. Each line gets one reasoned inline hypatia: allow directive per rule, as the scanner documents (ScannerSuppression.inline_allowed?/4: a directive on the line or the line above). Order of preference: fix > inline directive > .hypatia-ignore > baseline.

Changes

  • src/zig_ffi/chapel_bridge.zig and src/zig_ffi/runtime_owner.zig: comments only.
    • The line above each cast gets // hypatia: allow code_safety/zig_ptr_cast -- <reason>.
    • The cast line itself gets a trailing // hypatia: allow code_safety/zig_align_cast -- <reason>.

RSR Quality Checklist

Required

  • No code change. Comments are inert to zig build.
  • No banned functions.

Testing

I couldn't build the Hypatia scanner here: hex.pm is unreachable through this environment's proxy. Instead I simulated the scanner's suppression logic. That means directive_re and inline_allowed?/4 at hypatia 82396d81, which is the CI pin, reimplemented in Perl. Results:

  • main: 18 unsuppressed findings (9 casts × 2 rules), matching the gate's flagged files.
  • this branch: 0.

Zig isn't available here either. The change is comments only, so the Chapel CI Zig build is unaffected. #464 has the same commit merged in; its gate run is the real check.


Generated by Claude Code

cargo audit fails on rmcp 3.5.0 (crates/echidna-mcp) with
RUSTSEC-2026-0457 (fixed >=3.7.0), RUSTSEC-2026-0461 (>=3.6.0) and
RUSTSEC-2026-0462 (>=3.9.0), published after main last passed the
Dependency audit check. `cargo update -p rmcp` moves rmcp and
rmcp-macros to 3.9.0, inside the existing "3" requirement; no other
entry changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019a95kk88TZ1iegsBK3kox3
`cargo fmt --check` fails on main (2ab7574) in five places in
src/rust/proof_search.rs, so rust-ci 'Cargo check + clippy + fmt' is
red on every PR. Formatting only; no code change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019a95kk88TZ1iegsBK3kox3
Hypatia's code_safety/zig_ptr_cast and zig_align_cast now flag the nine
`@ptrCast(@aligncast(raw))` lines in src/zig_ffi/chapel_bridge.zig and
src/zig_ffi/runtime_owner.zig as high, and the governance Hypatia
baseline gate is red on main (2ab7574) as a result.

Each of those lines recovers a callback's own `*@this()` from the
type-erased `*anyopaque` it was registered with (runtime_owner.Work
.context, or a std.mem.Allocator vtable's ptr), so the cast restores the
original type and alignment. Fixed at source with a reasoned inline
`hypatia: allow` per rule on each line, as the scanner documents,
rather than a baseline entry. No code change: comments only.

Checked by simulating ScannerSuppression.inline_allowed?/4 and
directive_re at hypatia 82396d81 (the CI pin): 18 unsuppressed
findings on main, 0 with this change. The scanner itself could not be
built here (hex.pm is unreachable).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019a95kk88TZ1iegsBK3kox3
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 9b549f8f-ad29-4115-9313-ae2b6a20048d
Commits

Reviewing files that changed from the base of the PR and between 2ab7574 and 1e0d68a.

Files ignored due to path filters: 1

  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 3

  • src/rust/proof_search.rs
  • src/zig_ffi/chapel_bridge.zig
  • src/zig_ffi/runtime_owner.zig
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copy link
Copy Markdown
Owner Author

I've folded this into #465, which fixes all three checks that are red on main and has the same commit. Closing this one as a duplicate.


Generated by Claude Code

@sonarqubecloud

sonarqubecloud Bot commented Nov 9, 2026

Copy link
Copy Markdown

hyperpolymath added a commit that referenced this pull request Nov 9, 2026
…g casts) (#465)

## Summary

Three checks fail on `main` (`2ab7574`), so every open PR is red on
them. This PR fixes all three. It replaces #467 and
#468, which carried the same commits and are now
closed.

| Check | Cause | Fix (commit) |
|---|---|---|
| `Dependency audit`, `rust-ci / Cargo audit` | `rmcp` 3.5.0
(`crates/echidna-mcp`) has RUSTSEC-2026-0457, -0461 and -0462, published
after `main` last passed | `Cargo.lock` only: `rmcp` and `rmcp-macros`
move to 3.9.0, inside the existing `"3"` requirement (`20dc691`) |
| `rust-ci / Cargo check + clippy + fmt` | `cargo fmt --check` drift in
`src/rust/proof_search.rs` | `cargo fmt`, formatting only (`17ebbb1`) |
| `governance / Validate Hypatia Baseline` | Hypatia
`code_safety/zig_ptr_cast` and `zig_align_cast` are high on the nine
`@ptrCast(@aligncast(raw))` lines in `src/zig_ffi/` | A reasoned inline
`hypatia: allow` per rule on each line, with no baseline entry
(`f48fe0a`) |

Every one of those casts gets a callback's own `*@this()` back from the
type-erased `*anyopaque` it was registered with:
`runtime_owner.Work.context`, or a `std.mem.Allocator` vtable's `ptr`.
So each cast restores the pointer's original type and alignment. Order
of preference: fix > inline directive > `.hypatia-ignore` > baseline.

## Changes

- `Cargo.lock`: `rmcp` and `rmcp-macros` 3.5.0 → 3.9.0.
- `src/rust/proof_search.rs`: `rustfmt` only.
- `src/zig_ffi/chapel_bridge.zig` and `src/zig_ffi/runtime_owner.zig`:
comments only.

## RSR Quality Checklist

### Required

- [x] Code is formatted: `cargo fmt --all -- --check` passes.
- [x] Linter is clean: `cargo clippy --all-targets --locked -- -D
warnings` passes locally.
- [x] No secrets, credentials or `.env` files.

## Testing

- `cargo audit`: no vulnerabilities.
- `cargo check -p echidna-mcp --locked`: passes. The crate has no tests.
- Hypatia: the scanner could not be built here because hex.pm is
unreachable. I simulated its suppression logic instead: `directive_re`
and `ScannerSuppression.inline_allowed?/4` at hypatia `82396d81`, the CI
pin. That reports 18 unsuppressed findings on `main` (9 casts × 2 rules)
and 0 on this branch.
- Zig isn't available here. The Zig change is comments only, so it can't
affect the build.

## Checks still red, and not caused by this PR

- **`Deposit findings for gitbot-fleet`, `Isabelle/HOL`, `scan /
scan`:** also red on `main`.
- **`panic-attack assail`:** fails with "Scanner completion receipt is
missing, incomplete or inconsistent". It is also red on
#462 and #463.
- **`rust-ci / llvm-cov line coverage`** on `20dc691`:
- **What failed:**
`provers::chuffed::tests::version_requires_a_successful_help_response_and_closed_stdin`
exited with `Text file busy (os error 26)`.
- **Root cause:** `ETXTBSY`. A test writes its fake prover script and
then executes it. If another test thread forks in between, the child
inherits the still-open write descriptor, and the kernel refuses to
execute the file while it is open for writing. The same pattern exists
in the fixtures in `chuffed.rs`, `gpuverify.rs`, `faial.rs`,
`version_probe.rs` and `proof_search.rs`.
- **What I did:** re-ran the job once to confirm the failure is
intermittent.
- **Proposed fix (separate PR):** a shared test helper that retries the
spawn on `io::ErrorKind::ExecutableFileBusy`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_019a95kk88TZ1iegsBK3kox3

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants