`ZDIFFSTORE` and `ZINTERSTORE` with numkeys 0 crash the server (SIGSEGV)
Maintainers usually reply within 1 day
@siddiqueirshad is already working on this.
Since Oct 28, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
Research direction
Start with CommandZDiffStore::Parse and CommandZUnionStore::Parse in src/commands/cmd_zset.cc, then compare their numkeys validation with CommandZDiff::Parse and CommandZInter. Add coverage for zero numkeys to the relevant command tests and confirm both store commands return errors without crashing. Pull request #3731 is already open for this issue.
Written by the indexing model from the issue text.
Description
Search before asking
- I had searched in the issues and found no similar issues.
Version
Kvrocks 2.17.0 (commit 185d4221), Docker image apache/kvrocks:2.17.0 (same as latest), Linux
x86_64. The code involved is unchanged on unstable.
Minimal reproduce step
docker run -d --name kvrocks -p 6666:6666 apache/kvrocks:2.17.0
redis-cli -p 6666 ZADD s 1 a
redis-cli -p 6666 ZDIFFSTORE dst 0 s # server crashes
redis-cli -p 6666 ZINTERSTORE dst 0 AGGREGATE SUM # same, after the restart
What did you expect to see?
An error reply. The read-only commands already reject numkeys 0 (ZDIFF 0 s answers
ERR value is out of range, must be positive, ZINTER 0 s answers ERR out of numeric range),
and Redis answers ERR at least 1 input key is needed for 'zdiffstore' command.
What did you see instead?
The server process dies and every client loses its connection:
Ooops! Apache Kvrocks version 2.17.0 (commit 185d4221) got signal: Segmentation fault (11)
#2 ComposeNamespaceKey(rocksdb::Slice const&, rocksdb::Slice const&, bool)
#3 redis::Database::AppendNamespacePrefix(rocksdb::Slice const&)
#4 redis::ZSet::RangeByScore(...)
#5 redis::ZSet::Diff(...)
#6 redis::ZSet::DiffStore(...)
#7 redis::CommandZDiffStore::Execute(...)
Anything Else?
Potential cause. CommandZDiffStore::Parse (src/commands/cmd_zset.cc:1524-1538) and
CommandZUnionStore::Parse (:1200-1216, which ZINTERSTORE inherits) accept numkeys 0 and leave
the key list empty. ZSet::Diff then reads keys[0] (src/types/redis_zset.cc:905) and
ZSet::Inter reads keys_weights[0] (:657).
Suggested fix. Reject numkeys below 1 in both parsers, as CommandZDiff::Parse (:1472) and
CommandZInter (:1127) already do.
Are you willing to submit a PR?
- I'm willing to submit a PR!
- Dominant language
- C++
- Stars
- 4.5k
- Forks
- 686
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 40
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- Ships a Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/kvrocks
-
HSETEXPIRE with an overflowing TTL returns OK and deletes the whole hashPossibly taken @anubhavgupta121 claimed this 17 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
SSCAN, HSCAN, ZSCAN don't finish when an empty-string member is returned at the end of a pagePossibly taken @ggyuchive claimed this today. Openbug
Difficulty 3/5 1-2 days Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
`GEOSEARCH` / `GEORADIUS` with a negative radius hangsPossibly taken @ggyuchive claimed this 6 days ago. Openbug
Difficulty 3/5 1-2 days Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
Support the `SUNIONCARD` commandPossibly taken @PoisonGodv claimed this 2 days ago. Openenhancement
Difficulty 3/5 1-2 days Newbie friendliness 58/100
apache/kvrocks#3723 · 1 comment ·
Maintainers usually reply within 1 day
-
`NAMESPACE ADD/SET/DEL` and `CONFIG REWRITE` rewrite `kvrocks.conf` without fsync: after a power loss new namespaces vanish, and deleted namespaces / rotated tokens are valid againPossibly taken @Tyagiquamar claimed this 14 days ago. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 50/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
llvm/offload-test-suite#1703 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
BGI-shenzhen/PopLDdecay#25 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 68/100
eic/TimeframeBuilder#102 ·