Skip to content

Preserve nested DST padding in layout formulas - #3630

Open
joshlf wants to merge 1 commit into
mainfrom
Gxauzb34ce7e537xqailxsfsyzknfjcnl
Open

Preserve nested DST padding in layout formulas#3630
joshlf wants to merge 1 commit into
mainfrom
Gxauzb34ce7e537xqailxsfsyzknfjcnl

Conversation

@joshlf

@joshlf joshlf commented Sep 5, 2026

Copy link
Copy Markdown
Member

DstLayout flattened a nested slice DST's trailing-padding operation into the
alignment of its packed outer container. That could understate the Rust object
size, causing safe parsers and allocators to construct references and boxes
whose referents extended beyond their backing storage.

Represent slice-DST sizes as a normalized prefix plus an independently rounded
inner size. Carry that formula through composition, padding, metadata
inference, casts, projections, allocation, and split overlap checks. Add
regressions for the reported 8-byte-versus-10-byte packed layout, parsing,
allocation, zeroing, projection, metadata plateaus, and dynamic padding.

Closes #3617

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


Latest Update: v6 — Compare vs v5

📚 Full Patch History

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

Version v5 v4 v3 v2 v1 Base
v6 vs v5 vs v4 vs v3 vs v2 vs v1 vs Base
v5 vs v4 vs v3 vs v2 vs v1 vs 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/Gxauzb34ce7e537xqailxsfsyzknfjcnl && git checkout -b pr-Gxauzb34ce7e537xqailxsfsyzknfjcnl FETCH_HEAD

Checkout

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

Cherry Pick

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

Pull

git pull origin refs/heads/Gxauzb34ce7e537xqailxsfsyzknfjcnl

Stacked PRs enabled by GHerrit.

@codecov-commenter

codecov-commenter commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.51196% with 94 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.18%. Comparing base (2dad389) to head (3117a9b).

Files with missing lines Patch % Lines
zerocopy/src/layout.rs 71.18% 85 Missing ⚠️
zerocopy/src/lib.rs 92.59% 8 Missing ⚠️
zerocopy/src/util/mod.rs 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3630      +/-   ##
==========================================
- Coverage   91.85%   91.18%   -0.68%     
==========================================
  Files          20       20              
  Lines        6093     6443     +350     
==========================================
+ Hits         5597     5875     +278     
- Misses        496      568      +72     

☔ 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 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: 4fe26d3863

ℹ️ 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/mod.rs
// SAFETY: By invariant on `self`, the size of `T` with this
// metadata is no larger than `isize::MAX`, and thus cannot
// overflow `usize`.
None => unsafe { core::hint::unreachable_unchecked() },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Document the unchecked branch with the required citation

BLOCKING: This newly introduced unreachable_unchecked call is an unsafe block, but its safety comment lacks the versioned standard-library citation and quotation required by the repository's unsafe-review policy. Because reaching this arm is undefined behavior, add the relevant unreachable_unchecked safety text—for example, // [1] Per https://doc.rust-lang.org/1.92.0/std/hint/fn.unreachable_unchecked.html#safety: Reaching this function is Undefined Behavior.—and explicitly connect the MetadataOf and KnownLayout invariants to why size_for_metadata cannot return None.

AGENTS.md reference: zerocopy/AGENTS.md:L19-L23

Useful? React with 👍 / 👎.

@joshlf
joshlf force-pushed the Gxauzb34ce7e537xqailxsfsyzknfjcnl branch 2 times, most recently from 050855d to 2f7ebd0 Compare September 5, 2026 01:29
DstLayout flattened a nested slice DST's trailing-padding operation into the
alignment of its packed outer container. That could understate the Rust object
size, causing safe parsers and allocators to construct references and boxes
whose referents extended beyond their backing storage.

Represent slice-DST sizes as a normalized prefix plus an independently rounded
inner size. Carry that formula through composition, padding, metadata
inference, casts, projections, allocation, and split overlap checks. Add
regressions for the reported 8-byte-versus-10-byte packed layout, parsing,
allocation, zeroing, projection, metadata plateaus, and dynamic padding.

Closes #3617

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

gherrit-pr-id: Gxauzb34ce7e537xqailxsfsyzknfjcnl
@joshlf
joshlf force-pushed the Gxauzb34ce7e537xqailxsfsyzknfjcnl branch from 2f7ebd0 to 3117a9b Compare September 5, 2026 01:51
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: Nested packed DST layouts underallocate memory and permit out-of-bounds access

2 participants