Skip to content

Commit f4a29dc

Browse files
joshtriplettByron
authored andcommitted
Fix stat on files with timestamps before the epoch
stat converted the seconds to a `u64` before converting them to SystemTime. This would cause timestamps before the epoch to wrap around to timestamps near `u64::MAX`. Instead, pass the seconds as an i64. Convert it to SystemTime by computing an absolute Duration and then adding or subtracting as appropriate.
1 parent 5c57c6b commit f4a29dc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gix-index/src/fs.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ impl Metadata {
186186
}
187187

188188
#[cfg(not(windows))]
189-
fn system_time_from_secs_nanos(secs: u64, nanos: u32) -> SystemTime {
190-
std::time::UNIX_EPOCH + std::time::Duration::new(secs, nanos)
189+
fn system_time_from_secs_nanos(secs: i64, nanos: u32) -> SystemTime {
190+
let d = std::time::Duration::new(secs.abs_diff(0), nanos);
191+
if secs < 0 {
192+
std::time::UNIX_EPOCH - d
193+
} else {
194+
std::time::UNIX_EPOCH + d
195+
}
191196
}

0 commit comments

Comments
 (0)