mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Validate lock timeout range before acquire restrictions (#9061)
Preserve CPython signed nanosecond conversion precedence for reentrant and nonblocking acquisition, without changing the platform timeout maximum. Assisted-by: OpenAI Codex:model identifier unavailable
This commit is contained in:
1 parent
29f819ec40
commit
d23dc631ee
2 files changed
+15
No files matched your search
@@ -106,6 +106,11 @@ pub(crate) mod _thread {
|
||||
|
||||
fn validate_acquire_args(args: AcquireArgs, vm: &VirtualMachine) -> PyResult<(bool, f64)> {
|
||||
let timeout = args.timeout.to_secs_f64();
|
||||
// CPython checks the signed nanosecond range before acquire-specific restrictions.
|
||||
let timeout_ns = timeout * 1_000_000_000.0;
|
||||
if !(i64::MIN as f64..-(i64::MIN as f64)).contains(&timeout_ns) {
|
||||
return Err(vm.new_overflow_error("timestamp out of range for C PyTime_t"));
|
||||
}
|
||||
if !args.blocking && timeout != -1.0 {
|
||||
return Err(vm.new_value_error("can't specify a timeout for a non-blocking call"));
|
||||
}
|
||||
|
||||
@@ -9,6 +9,16 @@ for error, kwargs in (
|
||||
(ValueError, {"blocking": False, "timeout": 1}),
|
||||
(ValueError, {"timeout": -2}),
|
||||
(OverflowError, {"timeout": _thread.TIMEOUT_MAX + 1}),
|
||||
(OverflowError, {"blocking": False, "timeout": 2**63 / 1e9}),
|
||||
(OverflowError, {"blocking": False, "timeout": -9_223_372_037}),
|
||||
(OverflowError, {"timeout": -9_223_372_037}),
|
||||
(OverflowError, {"blocking": False, "timeout": float("inf")}),
|
||||
(OverflowError, {"timeout": float("inf")}),
|
||||
(OverflowError, {"blocking": False, "timeout": float("-inf")}),
|
||||
(OverflowError, {"timeout": float("-inf")}),
|
||||
(ValueError, {"timeout": -(2**63) / 1e9}),
|
||||
(ValueError, {"blocking": False, "timeout": 4_294_968}),
|
||||
(ValueError, {"timeout": -4_294_968}),
|
||||
):
|
||||
lock = _thread.RLock()
|
||||
assert lock.acquire()
|
||||
|
||||
Reference in new issue
Block a user