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 */