Skip to content

Commit 497d63f

Browse files
committed
Don't overflow in a converting stat times to u64
Closes #10297
1 parent aa78c3d commit 497d63f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/librustuv/file.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ impl FsRequest {
256256
let path = unsafe { Path::new(CString::new(path, false)) };
257257
let stat = self.get_stat();
258258
fn to_msec(stat: uvll::uv_timespec_t) -> u64 {
259-
(stat.tv_sec * 1000 + stat.tv_nsec / 1000000) as u64
259+
// Be sure to cast to u64 first to prevent overflowing if the tv_sec
260+
// field is a 32-bit integer.
261+
(stat.tv_sec as u64) * 1000 + (stat.tv_nsec as u64) / 1000000
260262
}
261263
let kind = match (stat.st_mode as c_int) & libc::S_IFMT {
262264
libc::S_IFREG => io::TypeFile,

0 commit comments

Comments
 (0)