Skip to content

Commit

Permalink
Relaxed RDB-version check in RESTORE
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Söderqvist <[email protected]>
  • Loading branch information
zuiderkwast committed Jan 22, 2025
1 parent 60e4f8b commit e3003b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ int verifyDumpPayload(unsigned char *p, size_t len, uint16_t *rdbver_ptr) {
if (rdbver_ptr) {
*rdbver_ptr = rdbver;
}
if (rdbver > RDB_VERSION) return C_ERR;
if ((rdbver >= RDB_FOREIGN_VERSION_MIN && rdbver <= RDB_FOREIGN_VERSION_MAX) ||
(rdbver > RDB_VERSION && server.rdb_version_check == RDB_VERSION_CHECK_STRICT)) {
return C_ERR;
}

if (server.skip_checksum_validation) return C_OK;

Expand Down
19 changes: 19 additions & 0 deletions tests/unit/dump.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ start_server {tags {"dump"}} {
close_replication_stream $repl
} {} {needs:repl}

test {RESTORE key with future RDB version, strict version check} {
# str len RDB 222 CRC64 checksum
# | | | |
set bar_dump "\x00\x03bar\xde\x00\x0fYUza\xd3\xec\xe0"
catch {r restore foo 0 $bar_dump replace} e
set e
} {ERR DUMP payload version or checksum are wrong}

test {RESTORE key with future RDB version, relaxed version check} {
# str len RDB 222 CRC64 checksum
# | | | |
set bar_dump "\x00\x03bar\xde\x00\x0fYUza\xd3\xec\xe0"
r config set rdb-version-check relaxed
catch {r restore foo 0 $bar_dump replace} e
r config set rdb-version-check strict
assert_equal {bar} [r get foo]
set e
} {OK}

test {DUMP of non existing key returns nil} {
r dump nonexisting_key
} {}
Expand Down

0 comments on commit e3003b3

Please sign in to comment.