From 3a4528df68c2dc25595c6d7fb5ee934755b35f74 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Mon, 1 Jul 2024 05:14:53 +0000 Subject: [PATCH] Avoid serializing/deserializing uninitialized slots This avoids errors under ASAN. --- .../parallel_hashmap/phmap_dump.h | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/parallel_hashmap/parallel_hashmap/phmap_dump.h b/lib/parallel_hashmap/parallel_hashmap/phmap_dump.h index 0f2018ef1..bf23928ca 100644 --- a/lib/parallel_hashmap/parallel_hashmap/phmap_dump.h +++ b/lib/parallel_hashmap/parallel_hashmap/phmap_dump.h @@ -68,10 +68,14 @@ bool raw_hash_set::dump(OutputArchive& ar) const { std::cerr << "Failed to dump ctrl_" << std::endl; return false; } - if (!ar.dump(reinterpret_cast(slots_), - sizeof(slot_type) * capacity_)) { - std::cerr << "Failed to dump slot_" << std::endl; - return false; + for (size_t i = 0; i < capacity_; ++i) { + if (IsFull(ctrl_[i])) { + if (!ar.dump(reinterpret_cast(slots_) + sizeof(slot_type) * i, + sizeof(slot_type))) { + std::cerr << "Failed to dump slot_ " << i << std::endl; + return false; + } + } } return true; } @@ -101,10 +105,15 @@ bool raw_hash_set::load(InputArchive& ar) { std::cerr << "Failed to load ctrl" << std::endl; return false; } - if (!ar.load(reinterpret_cast(slots_), - sizeof(slot_type) * capacity_)) { - std::cerr << "Failed to load slot" << std::endl; - return false; + for (size_t i = 0; i < capacity_; ++i) { + if (IsFull(ctrl_[i])) { + SanitizerUnpoisonObject(slots_ + i); + if (!ar.load(reinterpret_cast(slots_) + sizeof(slot_type) * i, + sizeof(slot_type))) { + std::cerr << "Failed to load slot_ " << i << std::endl; + return false; + } + } } return true; }