Repository navigation
[Repo Assist] fix(rust-guard): reject zero-size alloc and share runtime policy via Arc - #16745
Conversation
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE Notes: All 4 Part A/C reads succeeded. The github CLI proxy only exposes 23 read-only tools (no add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request), so no Part B write could be attempted — this confirms backend
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the zero-size allocation guard and shared-policy changes.
No open issues 🎉
What changed in this PR
Implements #16737’s Rust guard improvements: prevents zero-size allocation undefined behavior and reduces policy-copying overhead during resource and response labeling.
Changes:
- Returns
0for zero-size allocation requests before calling the allocator. - Shares the runtime policy through
Arc<PolicyContext>instead of deep-cloning it on each label call. - Adds a unit test covering zero-size allocation rejection.
| File | Description |
|---|---|
guards/github-guard/rust-guard/src/lib.rs |
Adds the allocation guard and regression test, and switches runtime policy storage to Arc. |
Review effort: Balanced (adaptive)
🤖 This is an automated PR from Repo Assist.
Implements both improvements from #16737.
Changes
alloc(0)guard:std::alloc::allocis undefined behaviour for zero-sized layouts.allocnow returns 0 forsize == 0, mirroring the existingdeallocguard. Latent hardening only; the host never passes 0 today.Arc<PolicyContext>:RUNTIME_POLICY_CONTEXTnow storesArc<PolicyContext>, so eachlabel_resource/label_responsecall does a refcount bump instead of a deep clone. Call sites are unchanged (&Arc<T>auto-derefs).Adds the unit test
alloc_rejects_zero_size_without_touching_allocator.Closes #16737
Trade-offs
None significant. Non-zero alloc/dealloc round-trips can't be tested natively (u32 pointer truncation), so only the zero-size path is tested.
Test Status
cargo test: 725 passed, 0 failedcargo build --target wasm32-wasip1 --release: failed in this sandbox while compiling theitoaandserde_coredependencies, which my change doesn't touch. The wasm32 target is probably not installed here; CI should confirm.rustfmtclean forlib.rs. A pre-existing diff intools.rs(~line 164) was left untouched.Add this agentic workflow to your repo
To install this agentic workflow, run