From b045fe4e174eb90e110d0cb1c34e0fdc61ed9cbf Mon Sep 17 00:00:00 2001 From: luozongle01 Date: Wed, 19 Feb 2025 11:01:15 +0800 Subject: [PATCH] Fix overflow on 32-bit systems when calculating idle time for eviction (#13804) the `dictGetSignedIntegerVal` function should be used here, because in some cases (especially on 32-bit systems) long may be 4 bytes, and the ttl time saved in expires is a unix timestamp (millisecond value), which is more than 4 bytes. In this case, we may not be able to get the correct idle time, which may cause eviction disorder, in other words, keys that should be evicted later may be evicted earlier. --- src/evict.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/evict.c b/src/evict.c index 059e82fe37..fe19ca1779 100644 --- a/src/evict.c +++ b/src/evict.c @@ -162,7 +162,7 @@ int evictionPoolPopulate(redisDb *db, kvstore *samplekvs, struct evictionPoolEnt idle = 255-LFUDecrAndReturn(o); } else if (server.maxmemory_policy == MAXMEMORY_VOLATILE_TTL) { /* In this case the sooner the expire the better. */ - idle = ULLONG_MAX - (long)dictGetVal(de); + idle = ULLONG_MAX - dictGetSignedIntegerVal(de); } else { serverPanic("Unknown eviction policy in evictionPoolPopulate()"); }