From 3ab38478fcc498ac577cead21d3142954772dddd Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 28 Mar 2026 04:03:02 +0000 Subject: [PATCH] Fix GH-21557: jewishtojd returns 0 for years >= 6000. The year >= 6000 upper bound introduced in GH-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. --- ext/calendar/jewish.c | 2 +- ext/calendar/tests/gh21557.phpt | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 ext/calendar/tests/gh21557.phpt diff --git a/ext/calendar/jewish.c b/ext/calendar/jewish.c index 19b87316eb14..b589c4cb2617 100644 --- a/ext/calendar/jewish.c +++ b/ext/calendar/jewish.c @@ -710,7 +710,7 @@ zend_long JewishToSdn( int yearLength; int lengthOfAdarIAndII; - if (year <= 0 || year >= 6000 || day <= 0 || day > 30) { + if (year <= 0 || year >= INT_MAX - 1 || day <= 0 || day > 30) { return (0); } switch (month) { diff --git a/ext/calendar/tests/gh21557.phpt b/ext/calendar/tests/gh21557.phpt new file mode 100644 index 000000000000..1aa5e65cb342 --- /dev/null +++ b/ext/calendar/tests/gh21557.phpt @@ -0,0 +1,24 @@ +--TEST-- +GH-21557 jewishtojd returns 0 for years >= 6000 +--CREDITS-- +oleibman +--EXTENSIONS-- +calendar +--FILE-- + +--EXPECT-- +yh=5995 rh=2537279 +yh=5996 rh=2537633 +yh=5997 rh=2538016 +yh=5998 rh=2538371 +yh=5999 rh=2538725 +yh=6000 rh=2539110 +yh=6001 rh=2539463 +yh=6002 rh=2539818 +yh=6003 rh=2540202 +yh=6004 rh=2540557