Skip to content

[BUG] EXPIRE and SETEX have inconsistent overflow handling #9825

@bmerry

Description

@bmerry

Describe the bug

SETEX is documented as being equivalent to doing (atomically) SET followed by EXPIRE. However, the code for checking for overflow in EXPIRE is different and only reports an invalid expiry time if multiplying by 1000 gives a negative time.

To reproduce

SETEX rejects an expiry time that is more than 2^63 ms:

127.0.0.1:6379> setex foo 18446744073709561 blah
(error) ERR invalid expire time in setex

EXPIRE accepts it, and expires the key about 10 seconds later.

127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> expire foo 18446744073709561
(integer) 1

Expected behavior

Expected EXPIRE to match the behaviour of SETEX, and reject expiry times that overflow when converted to absolute milliseconds. It looks like this helper function might be useful for having EXPIRE apply the same logic.

Additional information

By eyeball, #9601 looks like it might fix the bug. The PR description suggests that the author might not have realised that this fixes an actual bug rather than just a UBSan violation, and that the intent was not to backport it to stable branches (cc @tezc @oranagra).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions