RDB: handle encoding errors with rdbExitReportCorruptRDB().
Without such change, the diskless replicas, when loading RDB files from the socket will not abort when a broken RDB file gets loaded. This is potentially unsafe, because right now Redis is not able to guarantee that encoding errors are safe from the POV of memory corruptions (for instance the LZF library may not be safe against untrusted data?) so better to abort when the RDB file we are going to load is corrupted. Instead I/O errors are still returned to the caller without aborting, so that in case of short read the diskless replica can try again.
This commit is contained in:
parent
344f46380f
commit
a345fef285
13
src/rdb.c
13
src/rdb.c
@ -214,8 +214,9 @@ int rdbLoadLenByRef(rio *rdb, int *isencoded, uint64_t *lenptr) {
|
||||
if (rioRead(rdb,&len,8) == 0) return -1;
|
||||
*lenptr = ntohu64(len);
|
||||
} else {
|
||||
serverLog(LL_WARNING, "Unknown length encoding %d in rdbLoadLen()",type);
|
||||
return -1;
|
||||
rdbExitReportCorruptRDB(
|
||||
"Unknown length encoding %d in rdbLoadLen()",type);
|
||||
return -1; /* Never reached. */
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -281,8 +282,8 @@ void *rdbLoadIntegerObject(rio *rdb, int enctype, int flags, size_t *lenptr) {
|
||||
v = enc[0]|(enc[1]<<8)|(enc[2]<<16)|(enc[3]<<24);
|
||||
val = (int32_t)v;
|
||||
} else {
|
||||
serverLog(LL_WARNING, "Unknown RDB integer encoding type %d", enctype);
|
||||
return NULL;
|
||||
rdbExitReportCorruptRDB("Unknown RDB integer encoding type %d",enctype);
|
||||
return NULL; /* Never reached. */
|
||||
}
|
||||
if (plain || sds) {
|
||||
char buf[LONG_STR_SIZE], *p;
|
||||
@ -499,8 +500,8 @@ void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) {
|
||||
case RDB_ENC_LZF:
|
||||
return rdbLoadLzfStringObject(rdb,flags,lenptr);
|
||||
default:
|
||||
serverLog(LL_WARNING, "Unknown RDB encoding type %llu", (unsigned long long)len);
|
||||
return NULL;
|
||||
rdbExitReportCorruptRDB("Unknown RDB string encoding type %d",len);
|
||||
return NULL; /* Never reached. */
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user