From c0731582a5bfdb2e9d594cd6cf2712f80beb6369 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 17 Aug 2026 17:23:47 +0200 Subject: [PATCH] Enforce content file CRC as terminal by rejecting trailing data and terminating parse loop --- cmdline/state.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmdline/state.c b/cmdline/state.c index 359a4be5..69dc2479 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -3422,6 +3422,20 @@ static void state_read_content(struct snapraid_state* state, const char* path, S } crc_checked = 1; + + /* crc must be the end of the content file */ + c = sgetc(f); + if (c != EOF) { + /* LCOV_EXCL_START */ + log_fatal(ECONTENT, "Unexpected data after CRC in content file '%s' at offset %" PRIi64 "\n", path, stell(f)); + log_fatal(ECONTENT, "The content file '%s' is damaged or corrupted!\n", path); + log_fatal(ECONTENT, "To recover, rename or delete it and rerun the command.\n"); + log_fatal(ECONTENT, "SnapRAID will automatically fall back to the next healthy copy.\n"); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + + break; } else { /* LCOV_EXCL_START */ decoding_error(path, f);