Validate serialized info timestamps in content file parser to prevent 64-bit overflow

This commit is contained in:
Andrea Mazzoleni 2026-08-27 21:17:22 +02:00
parent e0c0ea3dcc
commit 0277da9178

View file

@ -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;