]> git.lizzy.rs Git - rust.git/commitdiff
`SetFileTime` doesn't allow setting the file time to `0xFFFF_FFFF_FFFF_FFFF`
authorbeetrees <b@beetr.ee>
Sat, 10 Sep 2022 10:33:23 +0000 (11:33 +0100)
committerbeetrees <b@beetr.ee>
Sat, 1 Oct 2022 02:23:08 +0000 (03:23 +0100)
library/std/src/sys/windows/fs.rs

index 155d0297e49acfdfd8881c948645acbbdcd4f9e9..ade00750c959cc2b1b096dc32d4092809b77a955 100644 (file)
@@ -572,6 +572,14 @@ pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
                 "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())
         })?;