From 65e1eac0617ffbec9c1c73a76c017bddcc9e3e3e Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 26 Aug 2026 20:38:14 +0200 Subject: [PATCH] Fix int64_t overflow on file size when decoding content file --- cmdline/state.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/cmdline/state.c b/cmdline/state.c index d0eb2470..cdee4e99 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -2319,6 +2319,15 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_STOP */ } + /* ensure the unsigned serialized size fits in signed data_off_t before conversion. */ + if (v_size > INT64_MAX) { + /* LCOV_EXCL_START */ + decoding_error(path, f); + log_fatal(ECONTENT, "Internal inconsistency: Invalid file size %" PRIu64 "!\n", v_size); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + if (state->block_size == 0) { /* LCOV_EXCL_START */ decoding_error(path, f); @@ -2758,6 +2767,15 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_STOP */ } + /* ensure the unsigned serialized size fits in signed data_off_t before conversion. */ + if (v_size > INT64_MAX) { + /* LCOV_EXCL_START */ + decoding_error(path, f); + log_fatal(ECONTENT, "Internal inconsistency: Invalid deallocated file size %" PRIu64 "!\n", v_size); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + ret = sgetb64(f, &v_mtime_sec); if (ret < 0) { /* LCOV_EXCL_START */ @@ -3360,6 +3378,15 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_STOP */ } + /* ensure the unsigned serialized size fits in signed data_off_t before conversion. */ + if (v_size > INT64_MAX) { + /* LCOV_EXCL_START */ + decoding_error(path, f); + log_fatal(ECONTENT, "Internal inconsistency: Invalid split file size %" PRIu64 "!\n", v_size); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + /* if we use this parity entry */ if (v_level < state->level) { /* if this split was removed from the configuration */