diff --git a/integration_tests/commands/http/bit_test.go b/integration_tests/commands/http/bit_test.go index a26456504..1d6418cde 100644 --- a/integration_tests/commands/http/bit_test.go +++ b/integration_tests/commands/http/bit_test.go @@ -481,6 +481,30 @@ func TestBitCount(t *testing.T) { }, Out: []interface{}{float64(0)}, }, + { + InCmds: []HTTPCommand{ + {Command: "SETBIT", Body: map[string]interface{}{"key": "mykey", "values": []interface{}{-1, 1}}}, + }, + Out: []interface{}{"ERR bit offset is not an integer or out of range"}, + }, + { + InCmds: []HTTPCommand{ + {Command: "SETBIT", Body: map[string]interface{}{"key": "mykey", "values": []interface{}{-1, 0}}}, + }, + Out: []interface{}{"ERR bit offset is not an integer or out of range"}, + }, + { + InCmds: []HTTPCommand{ + {Command: "SETBIT", Body: map[string]interface{}{"key": "mykey", "values": []interface{}{-10000, 1}}}, + }, + Out: []interface{}{"ERR bit offset is not an integer or out of range"}, + }, + { + InCmds: []HTTPCommand{ + {Command: "SETBIT", Body: map[string]interface{}{"key": "mykey", "values": []interface{}{-10000, 0}}}, + }, + Out: []interface{}{"ERR bit offset is not an integer or out of range"}, + }, { InCmds: []HTTPCommand{ {Command: "GETBIT", Body: map[string]interface{}{"key": "mykey", "values": []interface{}{122}}}, diff --git a/integration_tests/commands/resp/bit_test.go b/integration_tests/commands/resp/bit_test.go index 1861a2404..7d7d48212 100644 --- a/integration_tests/commands/resp/bit_test.go +++ b/integration_tests/commands/resp/bit_test.go @@ -280,6 +280,22 @@ func TestBitCount(t *testing.T) { InCmds: []string{"SETBIT mykey 122 1"}, Out: []interface{}{int64(0)}, }, + { + InCmds: []string{"SETBIT mykey -1 1"}, + Out: []interface{}{"ERR bit offset is not an integer or out of range"}, + }, + { + InCmds: []string{"SETBIT mykey -1 0"}, + Out: []interface{}{"ERR bit offset is not an integer or out of range"}, + }, + { + InCmds: []string{"SETBIT mykey -10000 1"}, + Out: []interface{}{"ERR bit offset is not an integer or out of range"}, + }, + { + InCmds: []string{"SETBIT mykey -10000 0"}, + Out: []interface{}{"ERR bit offset is not an integer or out of range"}, + }, { InCmds: []string{"GETBIT mykey 122"}, Out: []interface{}{int64(1)}, diff --git a/integration_tests/commands/websocket/bit_test.go b/integration_tests/commands/websocket/bit_test.go index 687b339d5..f2a97e5be 100644 --- a/integration_tests/commands/websocket/bit_test.go +++ b/integration_tests/commands/websocket/bit_test.go @@ -284,6 +284,22 @@ func TestBitCount(t *testing.T) { InCmds: []string{"SETBIT mykey 122 1"}, Out: []interface{}{float64(0)}, }, + { + InCmds: []string{"SETBIT mykey -1 1"}, + Out: []interface{}{"ERR bit offset is not an integer or out of range"}, + }, + { + InCmds: []string{"SETBIT mykey -1 0"}, + Out: []interface{}{"ERR bit offset is not an integer or out of range"}, + }, + { + InCmds: []string{"SETBIT mykey -10000 1"}, + Out: []interface{}{"ERR bit offset is not an integer or out of range"}, + }, + { + InCmds: []string{"SETBIT mykey -10000 0"}, + Out: []interface{}{"ERR bit offset is not an integer or out of range"}, + }, { InCmds: []string{"GETBIT mykey 122"}, Out: []interface{}{float64(1)}, diff --git a/internal/eval/store_eval.go b/internal/eval/store_eval.go index 7c6d9d2dd..d627c8b6f 100644 --- a/internal/eval/store_eval.go +++ b/internal/eval/store_eval.go @@ -5152,7 +5152,7 @@ func evalSETBIT(args []string, store *dstore.Store) *EvalResponse { key := args[0] offset, err := strconv.ParseInt(args[1], 10, 64) - if err != nil { + if err != nil || offset < 0 { return &EvalResponse{ Result: nil, Error: diceerrors.ErrGeneral("bit offset is not an integer or out of range"),