Repository navigation
Avoid 'grace' overflowing in process_kill() - #427
Conversation
- Validate `grace` and `close_connections` in `process_kill()` and require `is.finite(x)` in `is_nonneg_numeric_scalar()`. - Guard `processx_kill()` against non-scalar `grace` before reading `REAL(grace)[0]`. - Convert `grace` to milliseconds in `c_processx_kill()` without signed `int` overflow UB, clamping large values to `INT_MAX`, rounding positive sub-millisecond values up to `1`, and treating negative or `NaN` values as `0` instead of passing negative timeouts to `c_processx_wait()`.
|
Thanks! Would this actually happen? In any case it is worth capping the value and set a limit that fits into an integer. The PR seems overkill to me, the tests are also not really needed I think. Btw. if we are allowing these large values we should probably still allow |
|
Yes, the PR is definitely too large for a defensive case. I'll trim it down, but first, there's some possible contradiction here:
vs.
Are you thinking we should treat "very large" as |
|
Yes, I meant allowing values up to a cap, plus converting Inf to -1. |
- Revert `R/assertions.R` so `is_nonneg_numeric_scalar()` still allows `Inf`. - Keep `assert_that(is_nonneg_numeric_scalar(grace))` in `process_kill()` and drop the redundant C-level `TYPEOF`/`LENGTH` check and `is_flag(close_connections)`. - Flatten `c_processx_kill()` grace conversion to map `Inf` to `-1`, cap finite values `>= INT_MAX / 1000.0` at `INT_MAX` (before multiplying, avoiding `FE_OVERFLOW`), and leave `<= 0` / `NaN` as `0`. - Drop the extra tests in `tests/testthat/test-process.R` per review feedback.
|
OK, shrunk substantially. I interpreted "up to a cap" to mean "truncate at |
|
Thank you! |
Of course,
INT_MAXmilliseconds is about 25 days, so maybe setting a practical limit would also simplify the code here.As it stands, though, the
(int)(grace * 1000)can wraparound to negativegraceand cause indefinite hanging