sjh9714 2026-08-19 01:07:40 +0000 (Wed, 19 Aug 2026)
New Revision: c84cb4d4f3
https://github.com/ruby/ruby/commit/c84cb4d4f3
Log:
[ruby/date] Range-check the integral Rational offset
Every branch of offset_to_sec range-checks the resulting number of
seconds except one path through the Rational branch: when the day
fraction is an integral Rational, n is assigned inside the if arm and
reaches *rof without passing the guard that sits in the else arm.
DateTime.new(2024, 1, 1, 0, 0, 0, Rational(2, 1)) therefore produced a
48-hour offset, while the equivalent Integer 2 is rejected and falls
back to +00:00. Rational(49710, 1) is 4_294_944_000 seconds, over
INT_MAX, so the (int) narrowing turned a large positive offset into a
negative one.
Move the check below the if/else so it covers both arms. That also
bounds n before the narrowing. Rational(1, 1) is exactly
DAY_IN_SECONDS and the guard is inclusive, so in-range values are
unaffected.
https://github.com/ruby/date/commit/7524d7c41f
Modified files:
ext/date/date_core.c
test/date/test_date_new.rb