Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions libs/server/Resp/Objects/SortedSetCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private unsafe bool SortedSetMPop<TGarnetApi>(ref TGarnetApi storageApi)
}

// Validate we have enough arguments (no of keys + (MIN or MAX))
if (parseState.Count < numKeys + 2)
if (parseState.Count - 2 < numKeys)
{
return AbortWithErrorMessage(CmdStrings.RESP_SYNTAX_ERROR);
}
Expand Down Expand Up @@ -1068,7 +1068,7 @@ private unsafe bool SortedSetIntersect<TGarnetApi>(ref TGarnetApi storageApi)
return AbortWithErrorMessage(CmdStrings.GenericErrAtLeastOneKey, nameof(RespCommand.ZINTER));
}

if (parseState.Count < nKeys + 1)
if (parseState.Count - 1 < nKeys)
{
return AbortWithErrorMessage(CmdStrings.RESP_SYNTAX_ERROR);
}
Expand Down Expand Up @@ -1191,7 +1191,7 @@ private unsafe bool SortedSetIntersectLength<TGarnetApi>(ref TGarnetApi storageA
return AbortWithErrorMessage(CmdStrings.GenericErrAtLeastOneKey, nameof(RespCommand.ZINTERCARD));
}

if (parseState.Count < nKeys + 1)
if (parseState.Count - 1 < nKeys)
{
return AbortWithErrorMessage(CmdStrings.RESP_SYNTAX_ERROR);
}
Expand Down Expand Up @@ -1363,7 +1363,7 @@ private unsafe bool SortedSetUnion<TGarnetApi>(ref TGarnetApi storageApi)
return AbortWithErrorMessage(CmdStrings.GenericErrAtLeastOneKey, nameof(RespCommand.ZUNION));
}

if (parseState.Count < nKeys + 1)
if (parseState.Count - 1 < nKeys)
{
return AbortWithErrorMessage(CmdStrings.RESP_SYNTAX_ERROR);
}
Expand Down Expand Up @@ -1493,7 +1493,7 @@ private unsafe bool SortedSetUnionStore<TGarnetApi>(ref TGarnetApi storageApi)
return AbortWithErrorMessage(CmdStrings.GenericErrAtLeastOneKey, nameof(RespCommand.ZUNIONSTORE));
}

if (parseState.Count < nKeys + 2)
if (parseState.Count - 2 < nKeys)
{
return AbortWithErrorMessage(CmdStrings.RESP_SYNTAX_ERROR);
}
Expand Down
24 changes: 24 additions & 0 deletions test/standalone/Garnet.test.collections/RespSortedSetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5347,6 +5347,30 @@ public void CanDoZInterStoreWithBadNumKeysLC()
TestUtils.AssertEqualUpToExpectedLength(expectedResponse, response);
}

[Test]
public void CanDoSortedSetCommandsWithBadNumKeysLC()
{
using var lightClientRequest = TestUtils.CreateRequest();

// Same overflow as CanDoZInterStoreWithBadNumKeysLC, for the sibling commands.
var expectedResponse = $"-{Encoding.ASCII.GetString(CmdStrings.RESP_SYNTAX_ERROR)}\r\n+PONG\r\n";

var commands = new[]
{
"ZMPOP 2147483647 zset1 MIN",
"ZUNION 2147483647 zset1",
"ZUNIONSTORE dest 2147483647 zset1",
"ZINTER 2147483647 zset1",
"ZINTERCARD 2147483647 zset1",
};

foreach (var command in commands)
{
var response = lightClientRequest.SendCommands(command, "PING");
TestUtils.AssertEqualUpToExpectedLength(expectedResponse, response);
}
}

[Test]
public void ZInterResultOrder()
{
Expand Down
Loading