Skip to content

Commit 33d4160

Browse files
committed
ext/Intl: Fix out-of-bounds argument positions in calendar date/time APIs
1 parent 37bb1c3 commit 33d4160

5 files changed

Lines changed: 61 additions & 3 deletions

File tree

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.4.22
44

5+
- Intl:
6+
. Fix incorrect argument positions in out-of-bounds errors for
7+
IntlCalendar::set() and IntlGregorianCalendar date/time construction.
8+
(Weilin Du)
9+
510
- MySQLnd:
611
. Fix persistent free of non-persistent connect_attr key (David Carlier).
712

ext/intl/calendar/calendar_methods.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@ U_CFUNC PHP_FUNCTION(intlcal_set)
391391
}
392392

393393
for (int i = 0; i < arg_num; i++) {
394-
/* Arguments start at 1 */
395-
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(args[i], i + 1);
394+
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(args[i], object ? i + 1 : i + 2);
396395
}
397396

398397
CALENDAR_METHOD_FETCH_OBJECT;

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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
IntlCalendar::set(): 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+
$cal = IntlCalendar::createInstance();
10+
11+
try {
12+
$cal->set(99999999999, 1, 1);
13+
} catch (Throwable $e) {
14+
echo $e->getMessage(), "\n";
15+
}
16+
17+
try {
18+
intlcal_set($cal, 1, 99999999999, 1);
19+
} catch (Throwable $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
?>
23+
--EXPECTF--
24+
Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d
25+
IntlCalendar::set(): Argument #1 ($year) must be between -2147483648 and 2147483647
26+
27+
Deprecated: Function intlcal_set() is deprecated since 8.4, use IntlCalendar::set(), IntlCalendar::setDate(), or IntlCalendar::setDateTime() instead in %s on line %d
28+
intlcal_set(): Argument #3 ($month) must be between -2147483648 and 2147483647
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)