[php-src] master: Merge branch 'PHP-8.4' into PHP-8.5

Weilin Du <[email protected]>
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Weilin Du (LamentXU123)
Date: 2026-07-07T22:24:34+08:00

Commit: https://github.com/php/php-src/commit/f0f26c747a9441f50eb5b995eb0b0793a2c503a3
Raw diff: https://github.com/php/php-src/commit/f0f26c747a9441f50eb5b995eb0b0793a2c503a3.diff

Merge branch 'PHP-8.4' into PHP-8.5

* PHP-8.4:
  ext/calendar: Fix integer overflow in GregorianToSdn() and JulianToJd() (#22604)

Changed paths:
  A  ext/calendar/tests/gh22602.phpt
  M  NEWS
  M  ext/calendar/gregor.c
  M  ext/calendar/julian.c


Diff:

diff --git a/NEWS b/NEWS
index b4e9f5701b08..2f00f144fbb8 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,10 @@ PHP                                                                        NEWS
   . Fixed bug GH-22206 (missing return in global register detection).
     (P3p111n0)
 
+- Calendar:
+  . Fixed bug GH-22602 (gregoriantojd() and juliantojd() integer overflow with
+    INT_MAX year). (arshidkv12)
+
 - DBA:
   . Fixed OOB read on malformed length field in dba flatfile handler. (alhudz)
 
diff --git a/ext/calendar/gregor.c b/ext/calendar/gregor.c
index 3aef7ae6ac50..eaee9c8c73c7 100644
--- a/ext/calendar/gregor.c
+++ b/ext/calendar/gregor.c
@@ -209,6 +209,7 @@ zend_long GregorianToSdn(
 
 	/* check for invalid dates */
 	if (inputYear == 0 || inputYear < -4714 ||
+		inputYear > INT_MAX - 4800 ||
 		inputMonth <= 0 || inputMonth > 12 ||
 		inputDay <= 0 || inputDay > 31) {
 		return (0);
diff --git a/ext/calendar/julian.c b/ext/calendar/julian.c
index baff0771532e..c24527941d3e 100644
--- a/ext/calendar/julian.c
+++ b/ext/calendar/julian.c
@@ -222,6 +222,7 @@ zend_long JulianToSdn(
 
 	/* check for invalid dates */
 	if (inputYear == 0 || inputYear < -4713 ||
+		inputYear > INT_MAX - 4800 ||
 		inputMonth <= 0 || inputMonth > 12 ||
 		inputDay <= 0 || inputDay > 31) {
 		return (0);
diff --git a/ext/calendar/tests/gh22602.phpt b/ext/calendar/tests/gh22602.phpt
new file mode 100644
index 000000000000..d165a0174094
--- /dev/null
+++ b/ext/calendar/tests/gh22602.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Bug GH-22602: (gregoriantojd() and juliantojd() integer overflow with INT_MAX year)
+--EXTENSIONS--
+calendar
+--FILE--
+<?php
+$max = PHP_INT_MAX > 2147483647 ? 2147483647 : PHP_INT_MAX;
+$min = PHP_INT_MAX > 2147483647 ? -2147483648 : PHP_INT_MIN;
+
+var_dump(gregoriantojd(5, 5, $max));
+var_dump(gregoriantojd(5, 5, $min));
+var_dump(juliantojd(5, 5, 2147483647));
+var_dump(juliantojd(5, 5, -2147483647));
+
+?>
+--EXPECT--
+int(0)
+int(0)
+int(0)
+int(0)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.