Skip to content

[Repo Assist] fix(rust-guard): reject zero-size alloc and share runtime policy via Arc - #16745

Merged
lpcox merged 2 commits into
mainfrom
repo-assist/improve-alloc-zero-size-arc-policy-20261118-ac5534184c772992
Nov 18, 2026
Merged

lpcox merged 2 commits into
mainfrom
repo-assist/improve-alloc-zero-size-arc-policy-20261118-ac5534184c772992

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This is an automated PR from Repo Assist.

Implements both improvements from #16737.

Changes

  1. alloc(0) guard: std::alloc::alloc is undefined behaviour for zero-sized layouts. alloc now returns 0 for size == 0, mirroring the existing dealloc guard. Latent hardening only; the host never passes 0 today.
  2. Arc<PolicyContext>: RUNTIME_POLICY_CONTEXT now stores Arc<PolicyContext>, so each label_resource/label_response call 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 failed
  • cargo build --target wasm32-wasip1 --release: failed in this sandbox while compiling the itoa and serde_core dependencies, which my change doesn't touch. The wasm32 target is probably not installed here; CI should confirm.
  • rustfmt clean for lib.rs. A pre-existing diff in tools.rs (~line 164) was left untouched.

Generated by Repo Assist · copilot · routed: sonnet55 high · ~59 AIC · ⊞ 9.5K · ◷
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@851905c06e905bf362a9f6cc54f912e3df747d55

@lpcox
lpcox marked this pull request as ready for review November 18, 2026 15:32
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 15:32
@github-actions

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads data ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) absent from catalog (no write attempted) BLOCKED ⚠️
C CLI reads data ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) gh unauthenticated, not exercised BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh unauthenticated, not exercised BLOCKED ⚠️

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 GITHUB_READ_ONLY=1 config, not an independent gateway DIFC check. gh auth status showed no authenticated host, so Parts D/E (REST + GraphQL writes) could not be exercised either. No write leaked in any part; the gaps are methodology limits, not enforcement failures.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 0 for 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)

@lpcox
lpcox merged commit 50865af into main Nov 18, 2026
28 checks passed
@lpcox
lpcox deleted the repo-assist/improve-alloc-zero-size-arc-policy-20261118-ac5534184c772992 branch November 18, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[rust-guard] Rust Guard: reject zero-size alloc and share runtime policy via Arc

2 participants