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;
|
if (rioRead(rdb,&len,8) == 0) return -1;
|
||||||
*lenptr = ntohu64(len);
|
*lenptr = ntohu64(len);
|
||||||
} else {
|
} else {
|
||||||
serverLog(LL_WARNING, "Unknown length encoding %d in rdbLoadLen()",type);
|
rdbExitReportCorruptRDB(
|
||||||
return -1;
|
"Unknown length encoding %d in rdbLoadLen()",type);
|
||||||
|
return -1; /* Never reached. */
|
||||||
}
|
}
|
||||||
return 0;
|
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);
|
v = enc[0]|(enc[1]<<8)|(enc[2]<<16)|(enc[3]<<24);
|
||||||
val = (int32_t)v;
|
val = (int32_t)v;
|
||||||
} else {
|
} else {
|
||||||
serverLog(LL_WARNING, "Unknown RDB integer encoding type %d", enctype);
|
rdbExitReportCorruptRDB("Unknown RDB integer encoding type %d",enctype);
|
||||||
return NULL;
|
return NULL; /* Never reached. */
|
||||||
}
|
}
|
||||||
if (plain || sds) {
|
if (plain || sds) {
|
||||||
char buf[LONG_STR_SIZE], *p;
|
char buf[LONG_STR_SIZE], *p;
|
||||||
@ -499,8 +500,8 @@ void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) {
|
|||||||
case RDB_ENC_LZF:
|
case RDB_ENC_LZF:
|
||||||
return rdbLoadLzfStringObject(rdb,flags,lenptr);
|
return rdbLoadLzfStringObject(rdb,flags,lenptr);
|
||||||
default:
|
default:
|
||||||
serverLog(LL_WARNING, "Unknown RDB encoding type %llu", (unsigned long long)len);
|
rdbExitReportCorruptRDB("Unknown RDB string encoding type %d",len);
|
||||||
return NULL;
|
return NULL; /* Never reached. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user