diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-06-22 21:06:28 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-06-22 21:53:13 +0200 |
commit | eb02425ef9678c85ff0879503859de06d68fb484 (patch) | |
tree | 1af3a502ddee880b7fc195dc6820a259aa0ec89e /Tests/AK/TestHashMap.cpp | |
parent | 7953bd839175696cc55a56969f0bff9598e08fcf (diff) | |
download | serenity-eb02425ef9678c85ff0879503859de06d68fb484.zip |
AK: Clear the previous and next pointers of deleted HashTable buckets
Usually the values of the previous and next pointers of deleted buckets
are never used, as they're not part of the main ordered bucket chain,
but if an in-place rehashing is done, which results in the bucket being
turned into a free bucket, the stale pointers will remain, at which
point any item that is inserted into said free-bucket will have either
a stale previous pointer if the HashTable was empty on insertion, or a
stale next pointer, resulting in undefined behaviour.
This commit also includes a new HashMap test that reproduces this issue
Diffstat (limited to 'Tests/AK/TestHashMap.cpp')
-rw-r--r-- | Tests/AK/TestHashMap.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Tests/AK/TestHashMap.cpp b/Tests/AK/TestHashMap.cpp index b7a284a8cd..8d46a3d612 100644 --- a/Tests/AK/TestHashMap.cpp +++ b/Tests/AK/TestHashMap.cpp @@ -201,3 +201,13 @@ TEST_CASE(basic_contains) EXPECT_EQ(map.remove(1), true); EXPECT_EQ(map.contains(1), false); } + +TEST_CASE(in_place_rehashing_ordered_loop_bug) +{ + OrderedHashMap<String, String> map; + map.set("yt.innertube::nextId", ""); + map.set("yt.innertube::requests", ""); + map.remove("yt.innertube::nextId"); + map.set("yt.innertube::nextId", ""); + VERIFY(map.keys().size() == 2); +} |