From 0277da9178c892d8d6267d1bac33ceef86bee74f Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 27 Aug 2026 21:17:22 +0200 Subject: [PATCH] Validate serialized info timestamps in content file parser to prevent 64-bit overflow --- cmdline/state.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmdline/state.c b/cmdline/state.c index d05d079f..3ee91ba6 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -2541,6 +2541,15 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_STOP */ } + /* ensure the unsigned serialized timestamp fits in signed time_t before conversion. */ + if (v_oldest > INT64_MAX) { + /* LCOV_EXCL_START */ + decoding_error(path, f); + log_fatal(ECONTENT, "Internal inconsistency: Invalid info oldest timestamp %" PRIu64 "!\n", v_oldest); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + v_pos = 0; while (v_pos < blockmax) { int bad; @@ -2585,6 +2594,15 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_STOP */ } + /* ensure the timestamp addition fits in signed time_t without overflow. */ + if (t64 > INT64_MAX - v_oldest) { + /* LCOV_EXCL_START */ + decoding_error(path, f); + log_fatal(ECONTENT, "Internal inconsistency: Invalid info timestamp %" PRIu64 "!\n", t64); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + /* analyze the flags */ bad = (flag & 2) != 0; rehash = (flag & 4) != 0;