From f1242022c741d69da3280a6a77059160e0434999 Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Wed, 24 Apr 2024 21:59:20 +0200 Subject: [PATCH] Include upstream patch to avoid dropping uninitialized memory in some cases --- 1fa1dcc.patch | 36 ++++++++++++++++++++++++++++++++++++ rust-hashbrown.spec | 3 +++ 2 files changed, 39 insertions(+) create mode 100644 1fa1dcc.patch diff --git a/1fa1dcc.patch b/1fa1dcc.patch new file mode 100644 index 0000000..b27eb8b --- /dev/null +++ b/1fa1dcc.patch @@ -0,0 +1,36 @@ +From 1fa1dcca990d4e9d112f154c83802167f69f4fe9 Mon Sep 17 00:00:00 2001 +From: Amanieu d'Antras +Date: Mon, 4 Mar 2024 17:38:02 +0000 +Subject: [PATCH] Fix index calculation in panic guard of clone_from_impl + +Previously, it was possible for an uninitialized element to be dropped +if all of the following occurred: +- `clone_from` was called where `T: !Copy`. +- The `clone` implementation of `T` panicked. +- The first bucket of the source `HashMap` contained an entry. +--- + src/raw/mod.rs | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/raw/mod.rs b/src/raw/mod.rs +index ddd4fe7c1..22c01f5e9 100644 +--- a/src/raw/mod.rs ++++ b/src/raw/mod.rs +@@ -3582,7 +3582,7 @@ impl RawTable { + // cloned so far. + let mut guard = guard((0, &mut *self), |(index, self_)| { + if T::NEEDS_DROP { +- for i in 0..=*index { ++ for i in 0..*index { + if self_.is_bucket_full(i) { + self_.bucket(i).drop(); + } +@@ -3596,7 +3596,7 @@ impl RawTable { + to.write(from.as_ref().clone()); + + // Update the index in case we need to unwind. +- guard.0 = index; ++ guard.0 = index + 1; + } + + // Successfully cloned all items, no need to clean up. diff --git a/rust-hashbrown.spec b/rust-hashbrown.spec index f76ae7c..1ce753a 100644 --- a/rust-hashbrown.spec +++ b/rust-hashbrown.spec @@ -13,6 +13,9 @@ License: MIT OR Apache-2.0 URL: https://crates.io/crates/hashbrown Source: %{crates_source} +# upstream patch to avoid dropping uninitialized memory in some cases +Patch: https://github.com/rust-lang/hashbrown/commit/1fa1dcc.patch + BuildRequires: cargo-rpm-macros >= 24 %global _description %{expand: