Skip to content
Open
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
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.4.22

- Intl:
. Fix incorrect argument positions in out-of-bounds errors for
IntlCalendar::set() and IntlGregorianCalendar date/time construction.
(Weilin Du)

- MySQLnd:
. Fix persistent free of non-persistent connect_attr key (David Carlier).

Expand Down
4 changes: 2 additions & 2 deletions ext/intl/calendar/calendar_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ U_CFUNC PHP_FUNCTION(intlcal_set)
}

for (int i = 0; i < arg_num; i++) {
/* Arguments start at 1 */
Copy link
Copy Markdown
Contributor Author

@LamentXU123 LamentXU123 May 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is another similar issue I've find in the code base. This is incorrect position. Can be tested with

<?php
$cal = IntlCalendar::createInstance();
try {
    $cal->set(99999999999, 1, 1);
} catch (Throwable $e) {
    echo $e->getMessage(), "\n";
}

Will return

IntlCalendar::set(): Argument #0 ($year) must be between -2147483648 and 2147483647

But I expected

IntlCalendar::set(): Argument #1 ($year) must be between -2147483648 and 2147483647

This have been added to the original post.

ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(args[i], i + 1);
/* Count from intlcal_set($calendar, ...), so date/time arguments start at #2. */
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(args[i], i + 2);
}

CALENDAR_METHOD_FETCH_OBJECT;
Expand Down
2 changes: 1 addition & 1 deletion ext/intl/calendar/gregoriancalendar_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static void _php_intlgregcal_constructor_body(
} else {
// From date/time (3, 5 or 6 arguments)
for (int i = 0; i < variant; i++) {
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(largs[i], hasThis() ? (i-1) : i);
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(largs[i], i + 1);
}

if (variant == 3) {
Expand Down
28 changes: 28 additions & 0 deletions ext/intl/tests/calendar_set_out_of_bounds.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
IntlCalendar::set(): out-of-bounds date/time arguments report correct positions
--EXTENSIONS--
intl
--SKIPIF--
<?php if (PHP_INT_SIZE != 8) die("skip: 64-bit only"); ?>
--FILE--
<?php
$cal = IntlCalendar::createInstance();

try {
$cal->set(99999999999, 1, 1);
} catch (Throwable $e) {
echo $e->getMessage(), "\n";
}

try {
intlcal_set($cal, 1, 99999999999, 1);
} catch (Throwable $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d
IntlCalendar::set(): Argument #1 ($year) must be between -2147483648 and 2147483647

Deprecated: Function intlcal_set() is deprecated since 8.4, use IntlCalendar::set(), IntlCalendar::setDate(), or IntlCalendar::setDateTime() instead in %s on line %d
intlcal_set(): Argument #3 ($month) must be between -2147483648 and 2147483647
26 changes: 26 additions & 0 deletions ext/intl/tests/gregoriancalendar___construct_out_of_bounds.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
IntlGregorianCalendar::__construct(): out-of-bounds date/time arguments report correct positions
--EXTENSIONS--
intl
--SKIPIF--
<?php if (PHP_INT_SIZE != 8) die("skip: 64-bit only"); ?>
--FILE--
<?php
try {
new IntlGregorianCalendar(99999999999, 1, 1);
} catch (Throwable $e) {
echo $e->getMessage(), "\n";
}

try {
intlgregcal_create_instance(1, 99999999999, 1);
} catch (Throwable $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
Deprecated: Calling IntlGregorianCalendar::__construct() with more than 2 arguments is deprecated, use either IntlGregorianCalendar::createFromDate() or IntlGregorianCalendar::createFromDateTime() instead in %s on line %d
IntlGregorianCalendar::__construct(): Argument #1 ($timezoneOrYear) must be between -2147483648 and 2147483647

Deprecated: Function intlgregcal_create_instance() is deprecated since 8.4, use IntlGregorianCalendar::__construct(), IntlGregorianCalendar::createFromDate(), or IntlGregorianCalendar::createFromDateTime() instead in %s on line %d
intlgregcal_create_instance(): Argument #2 ($localeOrMonth) must be between -2147483648 and 2147483647
Loading