-
Notifications
You must be signed in to change notification settings - Fork 927
hashtable: add bounds check in hashtableNext iterator #2611
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
base: unstable
Are you sure you want to change the base?
Conversation
e54a9cf
to
31e5445
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #2611 +/- ##
============================================
- Coverage 72.24% 72.03% -0.22%
============================================
Files 127 128 +1
Lines 70820 71041 +221
============================================
+ Hits 51167 51175 +8
- Misses 19653 19866 +213
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Uri!
Note that this is just for making it safe to call hashtableNext again when it has already returned false. It's not really needed, but it makes it easier to detect bad usage, or is it for convenience?
Isn't calling hashtableNext()
after the end a bug that we want to detect? Why not do an assert instead of graceful return then?
Prevent iteration beyond hashtable bounds by checking if iterator is already at the end before proceeding with the main iteration loop. This adds defensive bounds checking for table index and bucket index. Signed-off-by: Uri Yagelnik <[email protected]>
31e5445
to
6df1a9a
Compare
@uriyage let's also add unittest for this? |
Signed-off-by: Uri Yagelnik <[email protected]>
39f159b
to
c57878c
Compare
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Many times I've tried to reject adding dependencies from the low-level datastructures to the whole of the server globals and everything. Dependencies should be in the other direction, from high level to lower level components. |
We can just use Debug assert depends on a server config. That would prevent usage of this hashtable in non-server code (valkey-cli, valkey-benchmark). |
@madolson According to a commment above, Uri explained why:
I suppose we could wait for this use case to be upstreamed and then include this change at the same time. |
Couldn't they then just save the state? I agree, I feel like I would rather close this and re-open if that use case becomes public. I'm not sure what that case is. |
Prevent iteration beyond hashtable bounds by checking if iterator is already at the end before proceeding with the main iteration loop. This adds defensive bounds checking for table index and bucket index.