SetFileTime doesn't allow setting the file time to 0xFFFF_FFFF_FFFF_FFFF

This commit is contained in:
beetrees 2022-09-10 11:33:23 +01:00
parent 39c0b00cf9
commit c66860ab3e
No known key found for this signature in database
GPG Key ID: 8791BD754191EBD6

View File

@ -572,6 +572,14 @@ impl File {
"Cannot set file timestamp to 0",
));
}
let is_max =
|t: c::FILETIME| t.dwLowDateTime == c::DWORD::MAX && t.dwHighDateTime == c::DWORD::MAX;
if times.accessed.map_or(false, is_max) || times.modified.map_or(false, is_max) {
return Err(io::const_io_error!(
io::ErrorKind::InvalidInput,
"Cannot set file timestamp to 0xFFFF_FFFF_FFFF_FFFF",
));
}
cvt(unsafe {
c::SetFileTime(self.as_handle(), None, times.accessed.as_ref(), times.modified.as_ref())
})?;