Skip to content

Commit 7647b47

Browse files
committed
Fix phpGH-21557: jewishtojd returns 0 for years >= 6000.
The year >= 6000 upper bound introduced in phpGH-18849 was too restrictive as it is a valid year in the Jewish calendar. The overflow protection in MoladOfMetonicCycle already handles large values, the only guard needed is to prevent year + 1 from wrapping around INT_MAX. close phpGH-21558
1 parent bc8a95e commit 7647b47

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.3.31
44

5+
- Calendar:
6+
. Fixed bug GH-21557 (jewishtojd returns 0 for years >= 6000).
7+
(David Carlier)
8+
59

610
15 Jan 2026, PHP 8.3.30
711

ext/calendar/jewish.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ zend_long JewishToSdn(
714714
int yearLength;
715715
int lengthOfAdarIAndII;
716716

717-
if (year <= 0 || year >= 6000 || day <= 0 || day > 30) {
717+
if (year <= 0 || year >= INT_MAX - 1 || day <= 0 || day > 30) {
718718
return (0);
719719
}
720720
switch (month) {

ext/calendar/tests/gh21557.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GH-21557 jewishtojd returns 0 for years >= 6000
3+
--CREDITS--
4+
oleibman
5+
--EXTENSIONS--
6+
calendar
7+
--FILE--
8+
<?php
9+
for ($yh = 5995; $yh < 6005; ++$yh) {
10+
$rh = jewishtojd(1, 1, $yh);
11+
echo "yh=$yh rh=$rh\n";
12+
}
13+
?>
14+
--EXPECT--
15+
yh=5995 rh=2537279
16+
yh=5996 rh=2537633
17+
yh=5997 rh=2538016
18+
yh=5998 rh=2538371
19+
yh=5999 rh=2538725
20+
yh=6000 rh=2539110
21+
yh=6001 rh=2539463
22+
yh=6002 rh=2539818
23+
yh=6003 rh=2540202
24+
yh=6004 rh=2540557

0 commit comments

Comments
 (0)