Skip to content

Preserve source bytes after failed try_transmute - #3634

Open
joshlf wants to merge 1 commit into
mainfrom
Gosc7u5x37moad4qkehnrpfuziq62ctz3
Open

Preserve source bytes after failed try_transmute#3634
joshlf wants to merge 1 commit into
mainfrom
Gosc7u5x37moad4qkehnrpfuziq62ctz3

Conversation

@joshlf

@joshlf joshlf commented Sep 5, 2026

Copy link
Copy Markdown
Member

Validate the destination in place so a typed move cannot discard destination
padding before the original source is returned.

Closes #3632

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


Latest Update: v4 — Compare vs v3

📚 Full Patch History

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

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

Branch

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

Checkout

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

Cherry Pick

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

Pull

git pull origin refs/heads/Gosc7u5x37moad4qkehnrpfuziq62ctz3

Stacked PRs enabled by GHerrit.

@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-06T00:50:02.528375Z 30c0968 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.

@joshlf

joshlf commented Sep 5, 2026

Copy link
Copy Markdown
Member Author

@codex review

@codecov-commenter

codecov-commenter commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.86%. Comparing base (2dad389) to head (30c0968).

Files with missing lines Patch % Lines
zerocopy/src/macros.rs 92.85% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3634   +/-   ##
=======================================
  Coverage   91.85%   91.86%           
=======================================
  Files          20       20           
  Lines        6093     6106   +13     
=======================================
+ Hits         5597     5609   +12     
- Misses        496      497    +1     

☔ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: c69afe1da7

ℹ️ 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".

@joshlf
joshlf force-pushed the Gosc7u5x37moad4qkehnrpfuziq62ctz3 branch from c69afe1 to b96f646 Compare September 5, 2026 23:59
@joshlf

joshlf commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b96f64660b

ℹ️ 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/util/macro_util.rs Outdated

@joshlf joshlf left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This looks completely sound. However, I wonder whether we could slightly simplify by taking a Ptr::from_ref(&Src) and then using Ptr transmute operations to produce the argument to Dst::is_bit_valid (as opposed to using a union). It's also possible that, since we need to do a by-value transmute in the success path anyway, that approach wouldn't actually save any logic or code.

@joshlf
joshlf force-pushed the Gosc7u5x37moad4qkehnrpfuziq62ctz3 branch from b96f646 to 3fd222f Compare September 6, 2026 00:19
@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. Can't wait for the next one!

Reviewed commit: 3fd222fd70

ℹ️ 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".

Validate the destination in place so a typed move cannot discard destination
padding before the original source is returned.

Closes #3632

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

gherrit-pr-id: Gosc7u5x37moad4qkehnrpfuziq62ctz3
@joshlf
joshlf force-pushed the Gosc7u5x37moad4qkehnrpfuziq62ctz3 branch from 3fd222f to 30c0968 Compare September 6, 2026 00:45
@joshlf

joshlf commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

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

I adopted the suggested Ptr-based design in 30c0968. A literal Ptr::from_ref(&Src) is insufficient because Src: IntoBytes does not imply Src: Immutable, so the implementation places ReadOnly<Src> in ManuallyDrop, constructs a Ptr from that shared reference, and uses an exact-size transmute_with to obtain the candidate ReadOnly<Dst>. The valid branch performs one unaligned by-value read; the invalid branch extracts and returns the unchanged original Src.

This removes the bespoke union and most of its custom safety proof while preserving the required success and failure semantics. Nightly, stable, and MSRV UI tests, targeted regression tests, full nightly library tests, clippy, formatting, and an optimized-code comparison all pass.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 30c0968168

ℹ️ 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/util/macro_util.rs
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.

Security Advisory: Failed transmutations can disclose data from a previous response

2 participants