Fix int64_t overflow on file size when decoding content file

This commit is contained in:
Andrea Mazzoleni 2026-08-26 20:38:14 +02:00
parent fa81c20ee6
commit 65e1eac061

View file

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