fix: zunion and zunionstore zero numkeys bug (#1522)

Fixes #1442

Signed-off-by: rounaknandanwar <rounak.nandanwar@gmail.com>
This commit is contained in:
Rounak Nandanwar 2023-07-10 12:20:59 +05:30 committed by GitHub
parent 4eb2012a8d
commit 674f06875c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View file

@ -1445,12 +1445,14 @@ OpResult<KeyIndex> DetermineKeys(const CommandId* cid, CmdArgList args) {
if (!absl::SimpleAtoi(num, &num_custom_keys) || num_custom_keys < 0)
return OpStatus::INVALID_INT;
// TODO Fix this for Z family functions.
// Examples that crash: ZUNION 0 myset
if (name == "ZDIFF" && num_custom_keys == 0) {
return OpStatus::INVALID_INT;
}
if (name == "ZUNION" && num_custom_keys == 0) {
return OpStatus::SYNTAX_ERR;
}
if (args.size() < size_t(num_custom_keys) + num_keys_index + 1)
return OpStatus::SYNTAX_ERR;
}

View file

@ -956,7 +956,7 @@ OpResult<void> FillAggType(string_view agg, SetOpArgs* op_args) {
// Parse functions return the number of arguments read from CmdArgList
OpResult<unsigned> ParseAggregate(CmdArgList args, bool store, SetOpArgs* op_args) {
if (args.size() < 1) {
if (args.size() <= 1) {
return OpStatus::SYNTAX_ERR;
}

View file

@ -291,6 +291,9 @@ TEST_F(ZSetFamilyTest, ZUnionError) {
resp = Run({"zunion", "0"});
EXPECT_THAT(resp, ErrArg("wrong number of arguments"));
resp = Run({"zunion", "0", "myset"});
EXPECT_THAT(resp, ErrArg("syntax error"));
resp = Run({"zunion", "3", "z1", "z2", "z3", "weights", "1", "1", "k"});
EXPECT_THAT(resp, ErrArg("weight value is not a float"));
@ -360,6 +363,9 @@ TEST_F(ZSetFamilyTest, ZUnionStore) {
resp = Run({"zunionstore", "key", "0"});
EXPECT_THAT(resp, ErrArg("wrong number of arguments"));
resp = Run({"zunionstore", "key", "0", "aggregate"});
EXPECT_THAT(resp, ErrArg("syntax error"));
resp = Run({"zunionstore", "key", "0", "aggregate", "sum"});
EXPECT_THAT(resp, ErrArg("at least 1 input key is needed"));
resp = Run({"zunionstore", "key", "-1", "aggregate", "sum"});