This is an automated email from the ASF dual-hosted git repository.
twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new c2c5d094d fix(command): Enhance zdiff parse error case to avoid crash
(#3316)
c2c5d094d is described below
commit c2c5d094d4335c4951f88e7de319d78e1bf5b3b8
Author: Byeonggyu Park <[email protected]>
AuthorDate: Tue Dec 30 02:48:16 2025 +0900
fix(command): Enhance zdiff parse error case to avoid crash (#3316)
closes #3315
---
src/commands/cmd_zset.cc | 1 +
tests/gocase/unit/type/zset/zset_test.go | 8 ++++++++
2 files changed, 9 insertions(+)
diff --git a/src/commands/cmd_zset.cc b/src/commands/cmd_zset.cc
index 351ffb7d5..1d943e8ef 100644
--- a/src/commands/cmd_zset.cc
+++ b/src/commands/cmd_zset.cc
@@ -1469,6 +1469,7 @@ class CommandZDiff : public Commander {
auto parse_result = ParseInt<int>(args[1], 10);
if (!parse_result) return {Status::RedisParseErr, errValueNotInteger};
+ if (*parse_result <= 0) return {Status::RedisParseErr,
errValueMustBePositive};
numkeys_ = *parse_result;
if (numkeys_ > args.size() - 2) return {Status::RedisParseErr,
errInvalidSyntax};
diff --git a/tests/gocase/unit/type/zset/zset_test.go
b/tests/gocase/unit/type/zset/zset_test.go
index 774155a02..6f5effde9 100644
--- a/tests/gocase/unit/type/zset/zset_test.go
+++ b/tests/gocase/unit/type/zset/zset_test.go
@@ -1497,6 +1497,14 @@ func basicTests(t *testing.T, rdb *redis.Client, ctx
context.Context, enabledRES
})
}
+ t.Run(fmt.Sprintf("ZDIFF with invalid syntax - %s", encoding), func(t
*testing.T) {
+ require.Error(t, rdb.Do(ctx, "zdiff").Err())
+ require.Error(t, rdb.Do(ctx, "zdiff", "1").Err())
+ require.Error(t, rdb.Do(ctx, "zdiff", "-2", "key1",
"key2").Err())
+ require.Error(t, rdb.Do(ctx, "zdiff", "0", "key1").Err())
+ require.Error(t, rdb.Do(ctx, "zdiff", "3", "key1",
"key2").Err())
+ })
+
t.Run(fmt.Sprintf("ZDIFF with two sets - %s", encoding), func(t
*testing.T) {
createZset(rdb, ctx, "zseta", []redis.Z{
{Score: 1, Member: "a"},