INCR/DECR: no 64-bit overflow detection + non-standard non-integer error message #43

Open
opened 2026-06-10 12:49:40 +00:00 by sameh-farouk · 0 comments
Member

Summary

INCR / INCRBY / DECR / DECRBY have two semantic deviations from Redis:

  1. No overflow detection. Real Redis returns ERR increment or decrement would overflow. hero_db release builds (overflow-checks off) silently wrap at the i64 boundary.
  2. Non-standard error for non-integer values: ERR invalid integer value for key 'k': 'abc' instead of Redis's ERR value is not an integer or out of range.

Reproduction (vs redis 7.0.15)

SET k 9223372036854775807 ; INCR k  -> hero_db: -9223372036854775808 (wrapped)   redis: ERR ... overflow
SET k abc                 ; INCR k  -> hero_db: ERR invalid integer value...      redis: ERR value is not an integer or out of range

Root cause

crates/hero_db/src/db/engine/string.rs:81-100 (incrby):

  • let new_value = current + amount; — unchecked add.
  • RedisError::InvalidInteger { key, value } — non-standard message text.

Fix

Use i64::checked_add and return the overflow error on None; align the parse-error text with Redis (value is not an integer or out of range).


Filed from a Redis-compatibility audit (hero_db v0.6.0 @ main aacaad1). Every finding was cross-validated: the same probe passes on stock redis-server 7.0.15 and fails on hero_db, using the Apache Kvrocks gocase suite (Go) and a redis-py 8.0 probe (Python). Root causes verified against the source.

## Summary `INCR` / `INCRBY` / `DECR` / `DECRBY` have two semantic deviations from Redis: 1. **No overflow detection.** Real Redis returns `ERR increment or decrement would overflow`. hero_db release builds (`overflow-checks` off) **silently wrap** at the i64 boundary. 2. **Non-standard error for non-integer values:** `ERR invalid integer value for key 'k': 'abc'` instead of Redis's `ERR value is not an integer or out of range`. ## Reproduction (vs redis 7.0.15) ``` SET k 9223372036854775807 ; INCR k -> hero_db: -9223372036854775808 (wrapped) redis: ERR ... overflow SET k abc ; INCR k -> hero_db: ERR invalid integer value... redis: ERR value is not an integer or out of range ``` ## Root cause `crates/hero_db/src/db/engine/string.rs:81-100` (`incrby`): - `let new_value = current + amount;` — unchecked add. - `RedisError::InvalidInteger { key, value }` — non-standard message text. ## Fix Use `i64::checked_add` and return the overflow error on `None`; align the parse-error text with Redis (`value is not an integer or out of range`). --- *Filed from a Redis-compatibility audit (hero_db v0.6.0 @ main `aacaad1`). Every finding was cross-validated: the same probe **passes on stock `redis-server 7.0.15`** and **fails on hero_db**, using the Apache Kvrocks `gocase` suite (Go) and a `redis-py 8.0` probe (Python). Root causes verified against the source.*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_db#43
No description provided.