Skip to content

Commit be755c0

Browse files
committed
ext/Intl: Fix out-of-bounds argument positions for IntlGregorianCalendardate/time construction
1 parent 37bb1c3 commit be755c0

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
- OpenSSL:
1515
. Fix compatibility issues with OpenSSL 4.0. (jordikroon, Remi)
1616

17+
- Intl:
18+
. Fix incorrect argument positions in out-of-bounds errors for
19+
IntlGregorianCalendar date/time construction. (Weilin Du)
20+
1721
- SPL:
1822
. Fix SplFixedArray::setSize leak when destructor grows during clear.
1923
(David Carlier)

ext/intl/calendar/gregoriancalendar_methods.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static void _php_intlgregcal_constructor_body(
178178
} else {
179179
// From date/time (3, 5 or 6 arguments)
180180
for (int i = 0; i < variant; i++) {
181-
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(largs[i], hasThis() ? (i-1) : i);
181+
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(largs[i], i + 1);
182182
}
183183

184184
if (variant == 3) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
IntlGregorianCalendar::__construct(): out-of-bounds date/time arguments report correct positions
3+
--EXTENSIONS--
4+
intl
5+
--SKIPIF--
6+
<?php if (PHP_INT_SIZE != 8) die("skip: 64-bit only"); ?>
7+
--FILE--
8+
<?php
9+
try {
10+
new IntlGregorianCalendar(99999999999, 1, 1);
11+
} catch (Throwable $e) {
12+
echo $e->getMessage(), "\n";
13+
}
14+
15+
try {
16+
intlgregcal_create_instance(1, 99999999999, 1);
17+
} catch (Throwable $e) {
18+
echo $e->getMessage(), "\n";
19+
}
20+
?>
21+
--EXPECTF--
22+
Deprecated: Calling IntlGregorianCalendar::__construct() with more than 2 arguments is deprecated, use either IntlGregorianCalendar::createFromDate() or IntlGregorianCalendar::createFromDateTime() instead in %s on line %d
23+
IntlGregorianCalendar::__construct(): Argument #1 ($timezoneOrYear) must be between -2147483648 and 2147483647
24+
25+
Deprecated: Function intlgregcal_create_instance() is deprecated since 8.4, use IntlGregorianCalendar::__construct(), IntlGregorianCalendar::createFromDate(), or IntlGregorianCalendar::createFromDateTime() instead in %s on line %d
26+
intlgregcal_create_instance(): Argument #2 ($localeOrMonth) must be between -2147483648 and 2147483647

0 commit comments

Comments
 (0)