mirror of
https://github.com/fluencelabs/redis
synced 2025-06-01 03:31:18 +00:00
tryObjectEncoding(): don't call stringl2() for too big strings.
We are sure that a string that is longer than 21 chars cannot be represented by a 64 bit signed integer, as -(2^64) is 21 chars: strlen(-18446744073709551616) => 21
This commit is contained in:
parent
0f32c37fc9
commit
79a1d335c8
@ -278,6 +278,7 @@ int isObjectRepresentableAsLongLong(robj *o, long long *llval) {
|
|||||||
robj *tryObjectEncoding(robj *o) {
|
robj *tryObjectEncoding(robj *o) {
|
||||||
long value;
|
long value;
|
||||||
sds s = o->ptr;
|
sds s = o->ptr;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
if (o->encoding != REDIS_ENCODING_RAW)
|
if (o->encoding != REDIS_ENCODING_RAW)
|
||||||
return o; /* Already encoded */
|
return o; /* Already encoded */
|
||||||
@ -291,7 +292,8 @@ robj *tryObjectEncoding(robj *o) {
|
|||||||
redisAssertWithInfo(NULL,o,o->type == REDIS_STRING);
|
redisAssertWithInfo(NULL,o,o->type == REDIS_STRING);
|
||||||
|
|
||||||
/* Check if we can represent this string as a long integer */
|
/* Check if we can represent this string as a long integer */
|
||||||
if (!string2l(s,sdslen(s),&value)) return o;
|
len = sdslen(s);
|
||||||
|
if (len > 21 || !string2l(s,len,&value)) return o;
|
||||||
|
|
||||||
/* Ok, this object can be encoded...
|
/* Ok, this object can be encoded...
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user