Skip to content

Extract slice metadata without references - #3629

Open
joshlf wants to merge 2 commits into
mainfrom
Gro7m5vgpfdcy3pxtpl52hnbgworclnzw
Open

Extract slice metadata without references#3629
joshlf wants to merge 2 commits into
mainfrom
Gro7m5vgpfdcy3pxtpl52hnbgworclnzw

Conversation

@joshlf

@joshlf joshlf commented Sep 5, 2026

Copy link
Copy Markdown
Member

KnownLayout's slice implementation materialized a shared reference solely to
read raw pointer metadata. That is invalid for null, dangling, unaligned, or
otherwise non-dereferenceable slice pointers even though metadata extraction
itself must accept them.

Use the safe raw-slice pointer length API on Rust 1.79 and newer. On older
supported compilers, capture a metadata candidate through raw-pointer hashing
and authenticate it with raw slice pointer equality before returning it.
Strengthen the implementer contract and cover null, dangling, deallocated,
unaligned, derived-DST, and boundary-toolchain cases.

Closes #3615

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.


Latest Update: v2 — Compare vs v1

📚 Full Patch History

Links show the diff between the row version and the column version.

Version v1 Base
v2 vs v1 vs Base
v1 vs Base
⬇️ Download this PR

Branch

git fetch origin refs/heads/Gro7m5vgpfdcy3pxtpl52hnbgworclnzw && git checkout -b pr-Gro7m5vgpfdcy3pxtpl52hnbgworclnzw FETCH_HEAD

Checkout

git fetch origin refs/heads/Gro7m5vgpfdcy3pxtpl52hnbgworclnzw && git checkout FETCH_HEAD

Cherry Pick

git fetch origin refs/heads/Gro7m5vgpfdcy3pxtpl52hnbgworclnzw && git cherry-pick FETCH_HEAD

Pull

git pull origin refs/heads/Gro7m5vgpfdcy3pxtpl52hnbgworclnzw

Stacked PRs enabled by GHerrit.

Generated KnownLayout implementations called pointer_to_metadata through a
concrete trailing type. A same-named inherent method could therefore capture
the call and supply metadata that violates the unsafe trait's layout contract.

Emit a fully trait-qualified call for both the derived type and its generated
MaybeUninit form. Extend the output hygiene check to reject unqualified
associated-item syntax, and add compile-time and semantic regressions for an
inherent-method collision.

Closes #3621

*Authored by an AI agent acting on Josh Liebow-Feeser's behalf.*

gherrit-pr-id: Gkpenpjjuex55evmm52puxsa34xtjgc7t
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-06T22:02:36.347684Z 89f6867 Manual request
🔒 Security Review Completed 2026-09-06T22:06:09.543589Z 89f6867 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov-commenter

codecov-commenter commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.89%. Comparing base (7ac962f) to head (89f6867).

Additional details and impacted files
@@                          Coverage Diff                          @@
##           Gkpenpjjuex55evmm52puxsa34xtjgc7t    #3629      +/-   ##
=====================================================================
+ Coverage                              91.85%   91.89%   +0.03%     
=====================================================================
  Files                                     20       20              
  Lines                                   6093     6118      +25     
=====================================================================
+ Hits                                    5597     5622      +25     
  Misses                                   496      496              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joshlf

joshlf commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 2e0e5c5c55

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread zerocopy/src/lib.rs
Comment thread zerocopy/src/lib.rs Outdated
KnownLayout's slice implementation materialized a shared reference solely to
read raw pointer metadata. That is invalid for null, dangling, unaligned, or
otherwise non-dereferenceable slice pointers even though metadata extraction
itself must accept them.

Use the safe raw-slice pointer length API on Rust 1.79 and newer. On older
supported compilers, capture a metadata candidate through raw-pointer hashing
and authenticate it with raw slice pointer equality before returning it.
Strengthen the implementer contract and cover null, dangling, deallocated,
unaligned, derived-DST, and boundary-toolchain cases.

Closes #3615

*Authored by an AI agent acting on Josh Liebow-Feeser's behalf.*

gherrit-pr-id: Gro7m5vgpfdcy3pxtpl52hnbgworclnzw
@joshlf
joshlf force-pushed the Gro7m5vgpfdcy3pxtpl52hnbgworclnzw branch from 2e0e5c5 to 89f6867 Compare September 6, 2026 21:58
@joshlf

joshlf commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

@codex review

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 89f6867632

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 89f6867632

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Base automatically changed from Gkpenpjjuex55evmm52puxsa34xtjgc7t to main September 6, 2026 22:07
Comment thread zerocopy/src/lib.rs
Comment thread zerocopy/src/lib.rs

@jswrenn jswrenn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The alternative here is altering the contract of pointer_to_metadata to consume a NonNull, but I think that'd cause more churn than it's worth for what can instead be resolved by an extremely cute MSRV workaround.

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.

Soundness Advisory: Extracting metadata from a null raw slice creates an invalid reference

3 participants