Skip to content
Prev Previous commit
Next Next commit
Add explicit float bounds before nanosecond cast
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
  • Loading branch information
Copilot and youknowone committed Dec 25, 2025
commit 514b7164b00e5a15d2ffa7783df367ece8364b16
8 changes: 5 additions & 3 deletions crates/vm/src/convert/try_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ fn duration_from_f64_floor(f: f64, vm: &VirtualMachine) -> PyResult<std::time::D
}

let total_nanos = (f * NANOS_PER_SEC).floor();
let total_nanos_u128 = total_nanos
.to_u128()
.ok_or_else(|| vm.new_value_error("value out of range"))?;
if total_nanos < 0.0 || total_nanos > u128::MAX as f64 {
return Err(vm.new_value_error("value out of range"));
}

let total_nanos_u128 = total_nanos as u128;
if total_nanos_u128 > MAX_TOTAL_NANOS {
return Err(vm.new_value_error("value out of range"));
}
Expand Down