Skip to content

Commit 6f8ad6f

Browse files
committed
Validate timeout in ThreadHandle::join to prevent panic
1 parent 47cf683 commit 6f8ad6f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

crates/vm/src/stdlib/thread.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,17 @@ pub(crate) mod _thread {
10961096
let timeout_duration = match timeout.flatten() {
10971097
Some(t) => {
10981098
let secs = t.to_secs_f64();
1099-
(secs >= 0.0).then(|| Duration::from_secs_f64(secs))
1099+
if secs >= 0.0 {
1100+
let nanos = secs * 1_000_000_000.0;
1101+
if secs > TIMEOUT_MAX || nanos < 0.0 || !nanos.is_finite() {
1102+
return Err(vm.new_overflow_error(
1103+
"timestamp too large to convert to Rust Duration".to_owned(),
1104+
));
1105+
}
1106+
Some(Duration::from_secs_f64(secs))
1107+
} else {
1108+
None
1109+
}
11001110
}
11011111
_ => None,
11021112
};

0 commit comments

Comments
 (0)