Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hset_family): Fix crash on scan after expiry set #4802

Merged
merged 3 commits into from
Mar 20, 2025

Conversation

abhijat
Copy link
Contributor

@abhijat abhijat commented Mar 20, 2025

When expiry is set on an hset its members are migrated to a string map.

When creating a new entry in string map with TTL, we also set a bit on the stored pointer as metadata, this is set as 1 << 63. As a consequence when reading back the pointer, if expiry is set, we need to unset the same bit to get the correct address, this is done already in string map internals.

This change adds a similar AND operation in the scan code to unset the TTL bit before dereferencing the pointer.

fixes #4799

When expiry is set on an hset its members are migrated to a string map.

If a scan is performed on the hset, the code branch for string map
accessed the value pointer directly by loading the 64 bit value from the
object pointer.

When creating a new entry in string map with TTL, we also set a bit on
the stored pointer as metadata, this is set as 1 << 63.

As a result when loading back the pointer we need to unset the same bit
to get the correct address, this is done already in string map internals
but the scan code did not do this, resulting in segfault.

This change adds an AND operation to unset the TTL bit before
dereferencing the pointer.

Signed-off-by: Abhijat Malviya <[email protected]>
@abhijat abhijat force-pushed the abhijat/fix/hscan-segv-on-expiry-set branch from 0d840f1 to 329ac6c Compare March 20, 2025 05:29
@@ -147,6 +147,11 @@ class StringMap : public DenseSet {
void RandomPairs(unsigned int count, std::vector<sds>& keys, std::vector<sds>& vals,
bool with_value);

static constexpr uint64_t kValTtlBit = 1ULL << 63;
Copy link
Collaborator

@romange romange Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no need to move these constants here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, I had originally used the constant directly in hset_family.cc but now StringMap::GetValue method is used, moved these back.

@abhijat abhijat requested a review from romange March 20, 2025 08:11
Signed-off-by: Abhijat Malviya <[email protected]>
@abhijat abhijat merged commit 624e111 into main Mar 20, 2025
10 checks passed
@abhijat abhijat deleted the abhijat/fix/hscan-segv-on-expiry-set branch March 20, 2025 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SIGSEGV on HSCAN when field has a TTL
3 participants