Skip to content

Fix issue #4476 - #4477

Open
allenss-amazon wants to merge 2 commits into
valkey-io:unstablefrom
allenss-amazon:fix-string-ref
Open

Fix issue #4476#4477
allenss-amazon wants to merge 2 commits into
valkey-io:unstablefrom
allenss-amazon:fix-string-ref

Conversation

@allenss-amazon

Copy link
Copy Markdown
Member

Add a null check to avoid the crash.

Signed-off-by: Allen Samuels <allenss@amazon.com>
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 02b1cc99-b044-40ee-8de0-9975dae264c5

📥 Commits

Reviewing files that changed from the base of the PR and between 7917ec4 and 00179d7.

📒 Files selected for processing (1)
  • tests/unit/moduleapi/hash_stringref.tcl

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

hashTypeHasStringRef now returns false for absent hash fields. A module test covers the missing-field lookup after hashtable conversion.

Changes

Hash lookup safety

Layer / File(s) Summary
Guard missing hash entries
src/t_hash.c, tests/unit/moduleapi/hash_stringref.tcl
hashTypeHasStringRef checks for a missing entry before dereferencing it. The module test verifies that a nonexistent field returns 0 after conversion to hashtable encoding.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 00179

The PR adds a localized null check with accompanying tests, and no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies the issue being fixed and matches the null-check change.
Description check ✅ Passed The description accurately states that the change adds a null check to prevent a crash.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@valkey-review-bot valkey-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One regression-test gap remains for the newly handled missing-field path.

Comment thread src/t_hash.c
if (objectGetEncoding(o) == OBJ_ENCODING_LISTPACK) return false;
hashtable *ht = objectGetVal(o);
void **entry_ref = hashtableFindRef(ht, field);
if (!entry_ref) return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This crash path still has no regression coverage: tests/unit/moduleapi/hash_stringref.tcl only queries the existing field f. After hash.set_stringref has converted k to a hashtable, add assert_equal "0" [r hash.has_stringref k missing]; that specifically exercises hashtableFindRef() returning NULL and protects this guard.

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 78.71%. Comparing base (0fb02b7) to head (00179d7).

Files with missing lines Patch % Lines
src/t_hash.c 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #4477      +/-   ##
============================================
- Coverage     78.78%   78.71%   -0.07%     
============================================
  Files           170      170              
  Lines         89792    89793       +1     
============================================
- Hits          70742    70684      -58     
- Misses        19050    19109      +59     
Files with missing lines Coverage Δ
src/t_hash.c 95.46% <0.00%> (+<0.01%) ⬆️

... and 23 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.

hashTypeHasStringRef() returns early for listpack-encoded hashes, so the
NULL entry_ref deref is only reachable once the hash is converted to the
hashtable encoding. The test sets a stringref to force that conversion,
then queries a field that does not exist.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FS8pBvk33tMU16JM5q1tB9
Signed-off-by: Allen Samuels <allenss@amazon.com>
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.

1 participant