From 349ef3f6a0c6a1e351caabcc5ec57c8e49a0f4c8 Mon Sep 17 00:00:00 2001 From: Oran Agra Date: Mon, 1 Mar 2021 17:23:29 +0200 Subject: [PATCH] fix stream deep sanitization with deleted records (#8568) When sanitizing the stream listpack, we need to count the deleted records too. otherwise the last line that checks the next pointer fails. Add test to cover that state in the stream tests. --- src/t_stream.c | 3 ++- tests/integration/corrupt-dump-fuzzer.tcl | 1 + tests/integration/rdb.tcl | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/t_stream.c b/src/t_stream.c index 4a425fd78..18138bec5 100644 --- a/src/t_stream.c +++ b/src/t_stream.c @@ -3570,7 +3570,7 @@ int streamValidateListpackIntegrity(unsigned char *lp, size_t size, int deep) { p = next; if (!lpValidateNext(lp, &next, size)) return 0; /* deleted */ - lpGetIntegerIfValid(p, &valid_record); + int64_t deleted_count = lpGetIntegerIfValid(p, &valid_record); if (!valid_record) return 0; p = next; if (!lpValidateNext(lp, &next, size)) return 0; @@ -3589,6 +3589,7 @@ int streamValidateListpackIntegrity(unsigned char *lp, size_t size, int deep) { if (!valid_record || zero != 0) return 0; p = next; if (!lpValidateNext(lp, &next, size)) return 0; + entry_count += deleted_count; while (entry_count--) { if (!p) return 0; int64_t fields = master_fields, extra_fields = 3; diff --git a/tests/integration/corrupt-dump-fuzzer.tcl b/tests/integration/corrupt-dump-fuzzer.tcl index 2506205a5..4fb503b8e 100644 --- a/tests/integration/corrupt-dump-fuzzer.tcl +++ b/tests/integration/corrupt-dump-fuzzer.tcl @@ -32,6 +32,7 @@ proc generate_types {} { # add some metadata to the stream r xgroup create stream mygroup 0 set records [r xreadgroup GROUP mygroup Alice COUNT 2 STREAMS stream >] + r xdel stream [lindex [lindex [lindex [lindex $records 0] 1] 1] 0] r xack stream mygroup [lindex [lindex [lindex [lindex $records 0] 1] 0] 0] # create other non-collection types diff --git a/tests/integration/rdb.tcl b/tests/integration/rdb.tcl index 7df1e2f74..9e1c2651a 100644 --- a/tests/integration/rdb.tcl +++ b/tests/integration/rdb.tcl @@ -52,6 +52,7 @@ start_server [list overrides [list "dir" $server_path] keep_persistence true] { } r xgroup create stream mygroup 0 set records [r xreadgroup GROUP mygroup Alice COUNT 2 STREAMS stream >] + r xdel stream [lindex [lindex [lindex [lindex $records 0] 1] 1] 0] r xack stream mygroup [lindex [lindex [lindex [lindex $records 0] 1] 0] 0] set digest [r debug digest] r config set sanitize-dump-payload no