-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix overflow of rdbWriteRaw return value #8306
Conversation
e5d9916
to
cb62d5a
Compare
Hi @oranagra I think it makes sense, and we need to backport it to 6.0 because we already allow users to set |
yes, let's fix it. |
@ShooterIT Redis officially supports a maximum key and value of 512M, I think int(>2G) should be enough. |
@oranagra if the user saved exactly 4G, the int return value would be -1, that would fail the rdb saving directly.
|
negative number is represented by complement in computer system, so the length of data is #include <stdio.h>
int main(void) {
printf("%d\r\n",(int)((1UL<<32)-1));
}
./a.out
-1 The return value of ssize_t rdbSaveLzfBlob(rio *rdb, void *data, size_t compress_len,
size_t original_len) {
unsigned char byte;
ssize_t n, nwritten = 0;
/* Data compressed! Let's save it on disk */
byte = (RDB_ENCVAL<<6)|RDB_ENC_LZF;
if ((n = rdbWriteRaw(rdb,&byte,1)) == -1) goto writeerr;
nwritten += n;
if ((n = rdbSaveLen(rdb,compress_len)) == -1) goto writeerr;
nwritten += n;
if ((n = rdbSaveLen(rdb,original_len)) == -1) goto writeerr;
nwritten += n;
if ((n = rdbWriteRaw(rdb,data,compress_len)) == -1) goto writeerr;
nwritten += n;
return nwritten;
writeerr:
return -1;
} |
Saving string of more than 2GB to the RDB file, can result in corrupt RDB, or failure in rdbSave. S (cherry picked from commit 542455c)
Saving string of more than 2GB to the RDB file, can result in corrupt RDB, or failure in rdbSave. S
Fixes #8299
Just change the rdbWriteRaw return value type from
int
tossize_t
.This function is called about 20 places. Most of caller's input parameter
len
is in the range of int, so this change will just act on the functionrdbSaveLzfBlob
and functionrdbSaveRawString
when a string(>2GB) need to be written to rdb.