Skip to content

Don't drop uninit memory when MapWindows::clone panics#156588

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Jules-Bertholet:fix-panicky-mapwindows-clone
Jun 2, 2026
Merged

Don't drop uninit memory when MapWindows::clone panics#156588
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Jules-Bertholet:fix-panicky-mapwindows-clone

Conversation

@Jules-Bertholet
Copy link
Copy Markdown
Contributor

Fixes #156501, using the approach suggested in @bjorn3's comment #156517 (comment)

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 14, 2026

The Miri subtree was changed

cc @rust-lang/miri

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 14, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 14, 2026

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, scottmcm

Comment thread src/tools/miri/tests/pass/issues/issue-156501-mapwindows-panicking-clone.rs Outdated
Comment thread library/core/src/iter/adapters/map_windows.rs Outdated
Comment thread library/core/src/iter/adapters/map_windows.rs Outdated
@scottmcm
Copy link
Copy Markdown
Member

I'm leaving libs reviews.
@rustbot reroll

@rustbot rustbot assigned Mark-Simulacrum and unassigned scottmcm May 18, 2026
@rust-bors

This comment has been minimized.

Comment thread library/core/src/iter/adapters/map_windows.rs Outdated
Comment thread library/coretests/tests/iter/adapters/map_windows.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 21, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 21, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Jules-Bertholet
Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 31, 2026
@Jules-Bertholet Jules-Bertholet force-pushed the fix-panicky-mapwindows-clone branch from 9d22610 to 4d2dcb9 Compare May 31, 2026 14:31
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 31, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Copy link
Copy Markdown
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

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

@bors squash msg="Don't drop uninit memory when MapWindows::clone panics"

View changes since this review

fn clone(&self) -> Self {
let mut buffer = Buffer {
// Use `ManuallyDrop` until buffer is fully written to avoid dropping uninitialized elements on panic.
// (See `Buffer` rustdoc for safety invariant)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hm, I guess this works, but it seems like it might be easier to just delay initializing self.start until after the write / clone complete?

But either way seems fine.

@rust-bors

This comment has been minimized.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jun 1, 2026

🔨 2 commits were squashed into 4a647a5.

@rust-bors rust-bors Bot force-pushed the fix-panicky-mapwindows-clone branch from 92b3b09 to 4a647a5 Compare June 1, 2026 12:25
@Mark-Simulacrum
Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jun 1, 2026

📌 Commit 4a647a5 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 1, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 1, 2026
…dows-clone, r=Mark-Simulacrum

Don't drop uninit memory when `MapWindows::clone` panics

Fixes rust-lang#156501, using the approach suggested in @bjorn3's comment rust-lang#156517 (comment)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 1, 2026
…dows-clone, r=Mark-Simulacrum

Don't drop uninit memory when `MapWindows::clone` panics

Fixes rust-lang#156501, using the approach suggested in @bjorn3's comment rust-lang#156517 (comment)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 1, 2026
…dows-clone, r=Mark-Simulacrum

Don't drop uninit memory when `MapWindows::clone` panics

Fixes rust-lang#156501, using the approach suggested in @bjorn3's comment rust-lang#156517 (comment)
rust-bors Bot pushed a commit that referenced this pull request Jun 1, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #156085 (miri: require (almost) all 1-ZST arguments to be actually passed)
 - #155193 (Check arguments of attributes where no arguments are expected)
 - #156516 (nix: remove some unneeded variables)
 - #156562 (Resolving Windows environment test failures)
 - #156588 (Don't drop uninit memory when `MapWindows::clone` panics)
 - #156673 (Privacy: small cleanups)
 - #156817 (Add `#[unsafe_eii]` to unsafe EII UI tests)
 - #156924 (Use #[panic_handler] rather than #[lang = "panic_impl"])
 - #157055 (LLVM 23: Run AssignGUIDPass in some places)
 - #157108 (Add Xtensa va_arg assembly coverage)
 - #157220 (cg_ssa: a bit less `immediate_or_packed_pair`)
 - #157241 (Trace `?id.local_def_index` instead of `id` in `def_path_hash`)
 - #157242 (Tune backport Zulip messages)
rust-bors Bot pushed a commit that referenced this pull request Jun 1, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #156085 (miri: require (almost) all 1-ZST arguments to be actually passed)
 - #155193 (Check arguments of attributes where no arguments are expected)
 - #156516 (nix: remove some unneeded variables)
 - #156562 (Resolving Windows environment test failures)
 - #156588 (Don't drop uninit memory when `MapWindows::clone` panics)
 - #156673 (Privacy: small cleanups)
 - #156817 (Add `#[unsafe_eii]` to unsafe EII UI tests)
 - #156924 (Use #[panic_handler] rather than #[lang = "panic_impl"])
 - #157055 (LLVM 23: Run AssignGUIDPass in some places)
 - #157108 (Add Xtensa va_arg assembly coverage)
 - #157220 (cg_ssa: a bit less `immediate_or_packed_pair`)
 - #157241 (Trace `?id.local_def_index` instead of `id` in `def_path_hash`)
 - #157242 (Tune backport Zulip messages)
rust-bors Bot pushed a commit that referenced this pull request Jun 1, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #156085 (miri: require (almost) all 1-ZST arguments to be actually passed)
 - #155193 (Check arguments of attributes where no arguments are expected)
 - #156516 (nix: remove some unneeded variables)
 - #156562 (Resolving Windows environment test failures)
 - #156588 (Don't drop uninit memory when `MapWindows::clone` panics)
 - #156673 (Privacy: small cleanups)
 - #156817 (Add `#[unsafe_eii]` to unsafe EII UI tests)
 - #156924 (Use #[panic_handler] rather than #[lang = "panic_impl"])
 - #157055 (LLVM 23: Run AssignGUIDPass in some places)
 - #157108 (Add Xtensa va_arg assembly coverage)
 - #157220 (cg_ssa: a bit less `immediate_or_packed_pair`)
 - #157241 (Trace `?id.local_def_index` instead of `id` in `def_path_hash`)
 - #157242 (Tune backport Zulip messages)
@rust-bors rust-bors Bot merged commit 8c1c6c1 into rust-lang:main Jun 2, 2026
12 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 2, 2026
rust-timer added a commit that referenced this pull request Jun 2, 2026
Rollup merge of #156588 - Jules-Bertholet:fix-panicky-mapwindows-clone, r=Mark-Simulacrum

Don't drop uninit memory when `MapWindows::clone` panics

Fixes #156501, using the approach suggested in @bjorn3's comment #156517 (comment)
@Jules-Bertholet Jules-Bertholet deleted the fix-panicky-mapwindows-clone branch June 2, 2026 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MapWindows::clone is not panic-safe; panicking T::clone causes uninitialized memory to be dropped

6 participants