Issue #22061 has been reported by afurm (Andrii Furmanets). ---------------------------------------- Bug #22061: Regexp timeout accepts NaN and disables timeout https://bugs.ruby-lang.org/issues/22061 * Author: afurm (Andrii Furmanets) * Status: Open * ruby -v: ruby 4.1.0dev (2026-05-11T07:56:09Z master d0ea61cb87) +PRISM [arm64-darwin25] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- `Regexp.timeout=` and `Regexp.new(..., timeout:)` currently accept `Float::NAN`. The value passes the positive-timeout validation because `NaN <= 0` is false, and then `double2hrtime` stores it as a zero timeout value. This makes both APIs behave as if no timeout was configured: ```ruby p Regexp.new("foo", timeout: Float::NAN).timeout #=> nil Regexp.timeout = Float::NAN p Regexp.timeout #=> nil ``` `Float::NAN` is not a valid positive timeout value, so I expect it to raise `ArgumentError`, the same as `0` and negative values. Reproduced on master: ```text ruby 4.1.0dev (2026-05-11T07:56:09Z master d0ea61cb87) +PRISM [arm64-darwin25] ``` Proposed fix: Reject NaN in the shared regexp timeout validation helper before converting the double to `rb_hrtime_t`. Pull request: https://github.com/ruby/ruby/pull/16917 -- https://bugs.ruby-lang.org/