Skip to content

Commit da7c921

Browse files
authored
Avoid serializing/deserializing uninitialized slots (#651)
This avoids errors under ASAN.
1 parent 6534adf commit da7c921

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

lib/parallel_hashmap/parallel_hashmap/phmap_dump.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@ bool raw_hash_set<Policy, Hash, Eq, Alloc>::dump(OutputArchive& ar) const {
6868
std::cerr << "Failed to dump ctrl_" << std::endl;
6969
return false;
7070
}
71-
if (!ar.dump(reinterpret_cast<char*>(slots_),
72-
sizeof(slot_type) * capacity_)) {
73-
std::cerr << "Failed to dump slot_" << std::endl;
74-
return false;
71+
for (size_t i = 0; i < capacity_; ++i) {
72+
if (IsFull(ctrl_[i])) {
73+
if (!ar.dump(reinterpret_cast<char*>(slots_) + sizeof(slot_type) * i,
74+
sizeof(slot_type))) {
75+
std::cerr << "Failed to dump slot_ " << i << std::endl;
76+
return false;
77+
}
78+
}
7579
}
7680
return true;
7781
}
@@ -101,10 +105,15 @@ bool raw_hash_set<Policy, Hash, Eq, Alloc>::load(InputArchive& ar) {
101105
std::cerr << "Failed to load ctrl" << std::endl;
102106
return false;
103107
}
104-
if (!ar.load(reinterpret_cast<char*>(slots_),
105-
sizeof(slot_type) * capacity_)) {
106-
std::cerr << "Failed to load slot" << std::endl;
107-
return false;
108+
for (size_t i = 0; i < capacity_; ++i) {
109+
if (IsFull(ctrl_[i])) {
110+
SanitizerUnpoisonObject(slots_ + i);
111+
if (!ar.load(reinterpret_cast<char*>(slots_) + sizeof(slot_type) * i,
112+
sizeof(slot_type))) {
113+
std::cerr << "Failed to load slot_ " << i << std::endl;
114+
return false;
115+
}
116+
}
108117
}
109118
return true;
110119
}

0 commit comments

Comments
 (0)