[php-src] PR #23555: fix(frenchtojd): range-check zend_long args before narrowing to int
| From: | lacatoire | Date: | Thu, 03 Sep 2026 13:27:57 +0000 |
| Subject: | [php-src] PR #23555: fix(frenchtojd): range-check zend_long args before narrowing to int | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-38281@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/23555
Author: lacatoire
## Summary
FrenchToSdn() in ext/calendar/french.c takes C int
parameters. PHP_FUNCTION(frenchtojd) parses into zend_long but passes them
directly to FrenchToSdn(), causing implicit narrowing. Values whose low 32 bits alias
into the valid range (e.g. month = 1 + 2**32) bypass the guard in french.c
and return a valid-looking Julian Day instead of 0.
### Fix
Add an explicit range check against the zend_long variables in
PHP_FUNCTION(frenchtojd), before the call to FrenchToSdn(), mirroring the
guard that already exists inside the helper:
```c
if (year < 1 || year > 14 || month < 1 || month > 13 || day < 1 || day > 30) {
RETURN_LONG(0);
}
RETURN_LONG(FrenchToSdn(year, month, day));
```
Valid inputs and already-out-of-range values (no aliasing) are unaffected.
### Test added
ext/calendar/tests/frenchtojd_overflow.phpt covers the three aliased-overflow cases
(month, day, year each + 2**32) and confirms a valid call still returns the correct Julian Day.