Skip to content

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

Open
Jules-Bertholet wants to merge 3 commits into
rust-lang:mainfrom
Jules-Bertholet:fix-panicky-mapwindows-clone
Open

Don't drop uninit memory when MapWindows::clone panics#156588
Jules-Bertholet wants to merge 3 commits 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 on lines +43 to +44
//
// FIXME make these unsafe fields once that feature is ready
Copy link
Copy Markdown
Member

@RalfJung RalfJung May 15, 2026

Choose a reason for hiding this comment

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

Suggested change
//
// FIXME make these unsafe fields once that feature is ready

I don't think it's worth adding this FIXME to very single type with an invariant.

View changes since the review

Jules-Bertholet and others added 2 commits May 15, 2026 10:10
Co-authored-by: Ralf Jung <post@ralfj.de>
@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
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 19, 2026

☔ The latest upstream changes (presumably #156728) made this pull request unmergeable. Please resolve the merge conflicts.

// `clone()` could panic; `ManuallyDrop` guards against that.
// (We could instead just construct `self.as_array_ref().clone()`
// as a local on the stack before creating the buffer.
// That would avoid the leak amplification,
Copy link
Copy Markdown
Member

@joboet joboet May 21, 2026

Choose a reason for hiding this comment

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

But this doesn't do leak amplification, right? If the clone panics, all the elements that have already been cloned are dropped – the array clone implementation takes care of that.

View changes since the review


assert!(result.is_err());

// current impl does leak amplification
Copy link
Copy Markdown
Member

@joboet joboet May 21, 2026

Choose a reason for hiding this comment

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

I don't think it does? It's just that nothing has been cloned successfully yet, and all the existing elements will be dropped after this point.

View changes since the review

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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