Skip to content

Fix DECRBY with LLONG_MIN storing a wrapped value - #989

Open
0x5t4l1n wants to merge 1 commit into
Snapchat:mainfrom
0x5t4l1n:fix/decrby-llong-min-overflow
Open

0x5t4l1n wants to merge 1 commit into
Snapchat:mainfrom
0x5t4l1n:fix/decrby-llong-min-overflow

Conversation

@0x5t4l1n

@0x5t4l1n 0x5t4l1n commented Dec 3, 2026

Copy link
Copy Markdown

Fixes #982

What changed

decrbyCommand negates the decrement and passes it to incrDecrCommand. For LLONG_MIN the negation wraps back to LLONG_MIN, so adding it to a non-negative value does not trip the overflow check and a wrong number is stored (SET k 5, DECRBY k -9223372036854775808 gave -9223372036854775803). It now replies ERR decrement would overflow and leaves the key unchanged, matching Redis 7.0. The new test is in tests/unit/type/incr.tcl.

Testing

Built from this branch (make MALLOC=libc NO_MOTD=yes BUILD_TLS=no) and ran ./runtest --single unit/type/incr --clients 1: all tests pass, including the new one. The new test fails on the unfixed code ("Expected an error but nothing was caught"). Manual check: SET k 5; DECRBY k -9223372036854775808 -> error, GET k -> 5; DECRBY z 1 on LLONG_MIN still gives the existing "increment or decrement would overflow". I only ran the incr suite, not the full test suite.

AI-assisted (Claude Code).

DECRBY negates the decrement before calling incrDecrCommand(). -LLONG_MIN wraps back to LLONG_MIN, so adding it to a non-negative value passes the overflow check and stores a wrong number. Reply with "decrement would overflow" instead, as Redis 7.0 does, and add a regression test.

Fixes Snapchat#982

Signed-off-by: Stalin <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] DECRBY k -9223372036854775808 stores a wrapped value instead of failing (fixed in Redis 7.0, still in KeyDB 6.3.4)

1 participant