]> git.lizzy.rs Git - rust.git/commitdiff
Don't overflow in a converting stat times to u64
authorAlex Crichton <alex@alexcrichton.com>
Tue, 5 Nov 2013 23:30:42 +0000 (15:30 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 10 Nov 2013 09:37:11 +0000 (01:37 -0800)
Closes #10297

src/librustuv/file.rs

index e042b7744be7a24a9db20c17f0e5bf92ff28a7b9..5cbf2d0e2b74b19e75c8d3d748fe94d61c094a9e 100644 (file)
@@ -256,7 +256,9 @@ pub fn mkstat(&self) -> FileStat {
         let path = unsafe { Path::new(CString::new(path, false)) };
         let stat = self.get_stat();
         fn to_msec(stat: uvll::uv_timespec_t) -> u64 {
-            (stat.tv_sec * 1000 + stat.tv_nsec / 1000000) as u64
+            // Be sure to cast to u64 first to prevent overflowing if the tv_sec
+            // field is a 32-bit integer.
+            (stat.tv_sec as u64) * 1000 + (stat.tv_nsec as u64) / 1000000
         }
         let kind = match (stat.st_mode as c_int) & libc::S_IFMT {
             libc::S_IFREG => io::TypeFile,