Skip to content

Commit a781c0d

Browse files
Copilotyouknowone
andcommitted
Check nanosecond sign before duration bounds
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
1 parent efea81d commit a781c0d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

crates/vm/src/convert/try_from.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,13 @@ fn duration_from_f64_floor(f: f64, vm: &VirtualMachine) -> PyResult<std::time::D
162162
}
163163

164164
let total_nanos = (f * NANOS_PER_SEC).floor();
165-
if !(0.0..=MAX_TOTAL_NANOS as f64).contains(&total_nanos) {
165+
if total_nanos.is_sign_negative() {
166166
return Err(vm.new_value_error("value out of range"));
167167
}
168-
169168
let total_nanos_u128 = total_nanos as u128;
169+
if total_nanos_u128 > MAX_TOTAL_NANOS {
170+
return Err(vm.new_value_error("value out of range"));
171+
}
170172

171173
let secs = (total_nanos_u128 / NANOS_PER_SEC_U128) as u64;
172174
let nanos = (total_nanos_u128 % NANOS_PER_SEC_U128) as u32;

0 commit comments

Comments
 (0)