Commit c93b3d151f5 for php
commit c93b3d151f50a30dceb41744a42d42a76ef002c8
Author: Weilin Du <weilindu@php.net>
Date: Mon Nov 23 18:58:34 2026 +0800
ext/intl: Reject non-finite timestamps in IntlCalendar::setTime() (#25668)
Reject NaN and positive and negative infinity before calling ICU. Report
U_ILLEGAL_ARGUMENT_ERROR and preserve the calendar's previous timestamp.
Closes #25668
diff --git a/NEWS b/NEWS
index 60a6b22ed7b..e05845aa30b 100644
--- a/NEWS
+++ b/NEWS
@@ -82,6 +82,7 @@ PHP NEWS
list is empty. (Weilin Du)
. Fixed intl_error_name() truncating error codes outside the int range.
(lacatoire)
+ . Fixed IntlCalendar::setTime() accepting non-finite timestamps. (Weilin Du)
- JSON:
. Fixed json_decode() and json_validate() error messages. (lacatoire)
diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp
index 680a01b24c0..ca11fa96ead 100644
--- a/ext/intl/calendar/calendar_methods.cpp
+++ b/ext/intl/calendar/calendar_methods.cpp
@@ -270,6 +270,12 @@ U_CFUNC PHP_FUNCTION(intlcal_set_time)
CALENDAR_METHOD_FETCH_OBJECT;
+ if (UNEXPECTED(!zend_finite(time_arg))) {
+ intl_errors_set(CALENDAR_ERROR_P(co), U_ILLEGAL_ARGUMENT_ERROR,
+ "Timestamp must be finite", 0);
+ RETURN_FALSE;
+ }
+
co->ucal->setTime((UDate)time_arg, CALENDAR_ERROR_CODE(co));
INTL_METHOD_CHECK_STATUS(co, "Call to underlying method failed");
diff --git a/ext/intl/tests/calendar_setTime_non_finite.phpt b/ext/intl/tests/calendar_setTime_non_finite.phpt
new file mode 100644
index 00000000000..0d751526875
--- /dev/null
+++ b/ext/intl/tests/calendar_setTime_non_finite.phpt
@@ -0,0 +1,28 @@
+--TEST--
+IntlCalendar::setTime() rejects non-finite timestamps
+--CREDITS--
+Wong Wai Kin
+--EXTENSIONS--
+intl
+--FILE--
+<?php
+$calendar = IntlCalendar::createInstance('UTC');
+var_dump($calendar->setTime(1234));
+
+foreach ([NAN, INF, -INF] as $timestamp) {
+ var_dump($calendar->setTime($timestamp));
+ var_dump($calendar->getErrorCode() === U_ILLEGAL_ARGUMENT_ERROR);
+ var_dump($calendar->getTime());
+}
+?>
+--EXPECT--
+bool(true)
+bool(false)
+bool(true)
+float(1234)
+bool(false)
+bool(true)
+float(1234)
+bool(false)
+bool(true)
+float(1234)