Skip to content

Conversation

uriyage
Copy link
Contributor

@uriyage uriyage commented Sep 15, 2025

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.

Copy link

codecov bot commented Sep 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.03%. Comparing base (a47e8fa) to head (c57878c).
⚠️ Report is 22 commits behind head on unstable.

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     
Files with missing lines Coverage Δ
src/hashtable.c 89.35% <100.00%> (+0.04%) ⬆️

... and 28 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@zuiderkwast zuiderkwast left a 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]>
@uriyage uriyage force-pushed the hashtable-iterator-bounds branch from 31e5445 to 6df1a9a Compare September 15, 2025 11:44
@ranshid
Copy link
Member

ranshid commented Sep 17, 2025

@uriyage let's also add unittest for this?

Signed-off-by: Uri Yagelnik <[email protected]>
@uriyage uriyage force-pushed the hashtable-iterator-bounds branch from 39f159b to c57878c Compare October 5, 2025 10:21
@uriyage
Copy link
Contributor Author

uriyage commented Oct 5, 2025

@uriyage let's also add unittest for this?

Done

Copy link
Member

@ranshid ranshid left a comment

Choose a reason for hiding this comment

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

LGTM

@zuiderkwast
Copy link
Contributor

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.

@madolson
Copy link
Member

I somewhat agree with Viktor. We can add a debugAssert to severassert.h if we want, that is just a no-op.

I was also dubious of this PR, since it's just adding a defensive check. @uriyage @ranshid Are we still moving forward with this?

@zuiderkwast
Copy link
Contributor

I somewhat agree with Viktor. We can add a debugAssert to severassert.h if we want, that is just a no-op.

We can just use assert instead. The check in the asserts are very light-weight, not even heavier than checking if the debugging is enabled.

Debug assert depends on a server config. That would prevent usage of this hashtable in non-server code (valkey-cli, valkey-benchmark).

@zuiderkwast
Copy link
Contributor

@madolson According to a commment above, Uri explained why:

We have a use case where we don't save the iterator state and attempt to run it again.

I suppose we could wait for this use case to be upstreamed and then include this change at the same time.

@madolson
Copy link
Member

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.

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.

4 participants