Normalize legacy out-of-range content nanoseconds to STAT_NSEC_INVALID

This commit is contained in:
Andrea Mazzoleni 2026-10-01 08:41:43 +02:00
parent edb3cacb77
commit 5b402fc462

View file

@ -2548,15 +2548,20 @@ static void state_read_content(struct snapraid_state* state, const char* path, S
} }
ret = sgetb32(f, &v_mtime_nsec); ret = sgetb32(f, &v_mtime_nsec);
if (ret < 0 || v_mtime_nsec > 1000000000) { if (ret < 0) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
decoding_error(path, f); decoding_error(path, f);
os_abort(); os_abort();
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
/* STAT_NSEC_INVALID is encoded as 0 */ /*
if (v_mtime_nsec == 0) * STAT_NSEC_INVALID is encoded as 0.
* Values > 1000000000 can occur in content files written by SnapRAID <= 14.10
* on Windows for files with pre-1970 timestamps due to negative nanoseconds.
* Normalize them to STAT_NSEC_INVALID.
*/
if (v_mtime_nsec == 0 || v_mtime_nsec > 1000000000)
v_mtime_nsec = STAT_NSEC_INVALID; v_mtime_nsec = STAT_NSEC_INVALID;
else else
--v_mtime_nsec; --v_mtime_nsec;
@ -3008,15 +3013,20 @@ static void state_read_content(struct snapraid_state* state, const char* path, S
} }
ret = sgetb32(f, &v_mtime_nsec); ret = sgetb32(f, &v_mtime_nsec);
if (ret < 0 || v_mtime_nsec > 1000000000) { if (ret < 0) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
decoding_error(path, f); decoding_error(path, f);
os_abort(); os_abort();
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
/* STAT_NSEC_INVALID is encoded as 0 */ /*
if (v_mtime_nsec == 0) * STAT_NSEC_INVALID is encoded as 0.
* Values > 1000000000 can occur in content files written by SnapRAID <= 14.10
* on Windows for files with pre-1970 timestamps due to negative nanoseconds.
* Normalize them to STAT_NSEC_INVALID.
*/
if (v_mtime_nsec == 0 || v_mtime_nsec > 1000000000)
v_mtime_nsec = STAT_NSEC_INVALID; v_mtime_nsec = STAT_NSEC_INVALID;
else else
--v_mtime_nsec; --v_mtime_nsec;