[php-src] PR #23971: Fix cal_days_in_month() returning a negative day count at the calendar's boundary year
| From: | lacatoire | Date: | Mon, 28 Sep 2026 17:32:52 +0000 |
| Subject: | [php-src] PR #23971: Fix cal_days_in_month() returning a negative day count at the calendar's boundary year | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-38892@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/23971
Author: lacatoire
cal_days_in_month() computes a month's length by comparing its start Julian Day
Number to the next month's. For December, that means looking up January 1st of year +
1.
For the last representable year of the Gregorian/Julian calendars (2147478847, i.e.
INT32_MAX - 4800), year + 1 is out of range and the internal lookup
returns 0 instead of a real date. Only CAL_FRENCH had a fallback for this
end-of-range case; every other calendar silently subtracted against that 0 and returned
a large negative day count instead of raising.
```php
var_dump(cal_days_in_month(CAL_GREGORIAN, 12, 2147478847));
// int(-138352149257414216) before this fix
// ValueError: Invalid date, after
```
Fix: treat a still-zero sdn_next as an invalid date for every calendar, not just
CAL_FRENCH.