Commit 7524d7c
committed
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.1 parent 83eb9d4 commit 7524d7c
2 files changed
Lines changed: 17 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2621 | 2621 | | |
2622 | 2622 | | |
2623 | 2623 | | |
2624 | | - | |
2625 | | - | |
2626 | 2624 | | |
| 2625 | + | |
| 2626 | + | |
2627 | 2627 | | |
2628 | 2628 | | |
2629 | 2629 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
195 | 210 | | |
196 | 211 | | |
197 | 212 | | |
| |||
0 commit comments