Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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)
Expand Down
6 changes: 6 additions & 0 deletions ext/intl/calendar/calendar_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
28 changes: 28 additions & 0 deletions ext/intl/tests/calendar_setTime_non_finite.phpt
Original file line number Diff line number Diff line change
@@ -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)
Loading