Skip to content

Commit

Permalink
Fix key value in ThreadedRodeo deserialization
Browse files Browse the repository at this point in the history
The key is set to be the highest key seen, causing the insertion
immediately following the deserialization to create a collision in the
string map
  • Loading branch information
ytanay committed Sep 16, 2023
1 parent aed4fb5 commit 67f38a7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/threaded_rodeo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,9 @@ where
.expect("failed to allocate memory for interner");

for (string, key) in deser_map {
if key.into_usize() > highest {
highest = key.into_usize();
let next_key = key.into_usize() + 1;
if next_key > highest {
highest = next_key;
}

let allocated = unsafe {
Expand Down Expand Up @@ -1707,6 +1708,12 @@ mod tests {
let deser: ThreadedRodeo = serde_json::from_str(&ser).unwrap();
let deser2: ThreadedRodeo = serde_json::from_str(&ser2).unwrap();

// Verify that the "next" key is set correctly
assert_eq!(
rodeo.key.load(Ordering::Relaxed),
deser.key.load(Ordering::Relaxed)
);

for (correct_key, correct_str) in [(a, "a"), (b, "b"), (c, "c"), (d, "d")].iter().copied() {
assert_eq!(correct_key, deser.get(correct_str).unwrap());
assert_eq!(correct_key, deser2.get(correct_str).unwrap());
Expand Down

0 comments on commit 67f38a7

Please sign in to comment.