Skip to content

Commit 69b9ef2

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: ext/intl: Fix out-of-bounds argument positions in calendar date/time APIs.
2 parents f1c6357 + 0288015 commit 69b9ef2

6 files changed

Lines changed: 207 additions & 12 deletions

ext/intl/calendar/calendar_methods.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@ U_CFUNC PHP_FUNCTION(intlcal_set)
419419
}
420420

421421
for (int i = 0; i < arg_num; i++) {
422-
/* Arguments start at 1 */
423-
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(args[i], i + 1);
422+
/* Count from intlcal_set($calendar, ...), so date/time arguments start at #2. */
423+
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(args[i], i + 2);
424424
}
425425

426426
CALENDAR_METHOD_FETCH_OBJECT;
@@ -455,9 +455,10 @@ U_CFUNC PHP_METHOD(IntlCalendar, setDate)
455455
RETURN_THROWS();
456456
}
457457

458-
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(year, 1);
459-
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(month, 2);
460-
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(day, 3);
458+
/* These method-only APIs parse the object first, so the API argument positions are offset by +1. */
459+
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(year, 2);
460+
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(month, 3);
461+
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(day, 4);
461462

462463
CALENDAR_METHOD_FETCH_OBJECT;
463464

@@ -478,18 +479,19 @@ U_CFUNC PHP_METHOD(IntlCalendar, setDateTime)
478479
RETURN_THROWS();
479480
}
480481

481-
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(year, 1);
482-
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(month, 2);
483-
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(day, 3);
484-
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(hour, 4);
485-
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(minute, 5);
482+
/* These method-only APIs parse the object first, so the API argument positions are offset by +1. */
483+
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(year, 2);
484+
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(month, 3);
485+
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(day, 4);
486+
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(hour, 5);
487+
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(minute, 6);
486488

487489
CALENDAR_METHOD_FETCH_OBJECT;
488490

489491
if (second_is_null) {
490492
co->ucal->set((int32_t) year, (int32_t) month, (int32_t) day, (int32_t) hour, (int32_t) minute);
491493
} else {
492-
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(second, 6);
494+
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(second, 7);
493495
co->ucal->set((int32_t) year, (int32_t) month, (int32_t) day, (int32_t) hour, (int32_t) minute, (int32_t) second);
494496
}
495497
}

ext/intl/calendar/gregoriancalendar_methods.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, bool
176176
// From date/time (3, 5 or 6 arguments)
177177
GregorianCalendar *tmp;
178178
for (int i = 0; i < variant; i++) {
179-
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(largs[i], hasThis() ? (i-1) : i);
179+
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(largs[i], i + 1);
180180
}
181181

182182
if (variant == 3) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
IntlCalendar::setDate(): out-of-bounds 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->setDate(99999999999, 1, 1);
13+
} catch (Throwable $e) {
14+
echo $e->getMessage(), "\n";
15+
}
16+
17+
try {
18+
$cal->setDate(1, 99999999999, 1);
19+
} catch (Throwable $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
23+
try {
24+
$cal->setDate(1, 1, 99999999999);
25+
} catch (Throwable $e) {
26+
echo $e->getMessage(), "\n";
27+
}
28+
?>
29+
--EXPECT--
30+
IntlCalendar::setDate(): Argument #1 ($year) must be between -2147483648 and 2147483647
31+
IntlCalendar::setDate(): Argument #2 ($month) must be between -2147483648 and 2147483647
32+
IntlCalendar::setDate(): Argument #3 ($dayOfMonth) must be between -2147483648 and 2147483647
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
IntlCalendar::setDateTime(): out-of-bounds 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->setDateTime(99999999999, 1, 1, 1, 1, 1);
13+
} catch (Throwable $e) {
14+
echo $e->getMessage(), "\n";
15+
}
16+
17+
try {
18+
$cal->setDateTime(1, 99999999999, 1, 1, 1, 1);
19+
} catch (Throwable $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
23+
try {
24+
$cal->setDateTime(1, 1, 99999999999, 1, 1, 1);
25+
} catch (Throwable $e) {
26+
echo $e->getMessage(), "\n";
27+
}
28+
29+
try {
30+
$cal->setDateTime(1, 1, 1, 99999999999, 1, 1);
31+
} catch (Throwable $e) {
32+
echo $e->getMessage(), "\n";
33+
}
34+
35+
try {
36+
$cal->setDateTime(1, 1, 1, 1, 99999999999, 1);
37+
} catch (Throwable $e) {
38+
echo $e->getMessage(), "\n";
39+
}
40+
41+
try {
42+
$cal->setDateTime(1, 1, 1, 1, 1, 99999999999);
43+
} catch (Throwable $e) {
44+
echo $e->getMessage(), "\n";
45+
}
46+
?>
47+
--EXPECT--
48+
IntlCalendar::setDateTime(): Argument #1 ($year) must be between -2147483648 and 2147483647
49+
IntlCalendar::setDateTime(): Argument #2 ($month) must be between -2147483648 and 2147483647
50+
IntlCalendar::setDateTime(): Argument #3 ($dayOfMonth) must be between -2147483648 and 2147483647
51+
IntlCalendar::setDateTime(): Argument #4 ($hour) must be between -2147483648 and 2147483647
52+
IntlCalendar::setDateTime(): Argument #5 ($minute) must be between -2147483648 and 2147483647
53+
IntlCalendar::setDateTime(): Argument #6 ($second) must be between -2147483648 and 2147483647
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
try {
24+
$cal->set(1, 1, 1, 99999999999, 1);
25+
} catch (Throwable $e) {
26+
echo $e->getMessage(), "\n";
27+
}
28+
29+
try {
30+
$cal->set(1, 1, 1, 1, 99999999999, 1);
31+
} catch (Throwable $e) {
32+
echo $e->getMessage(), "\n";
33+
}
34+
35+
try {
36+
intlcal_set($cal, 1, 1, 1, 1, 1, 99999999999);
37+
} catch (Throwable $e) {
38+
echo $e->getMessage(), "\n";
39+
}
40+
?>
41+
--EXPECTF--
42+
Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d
43+
IntlCalendar::set(): Argument #1 ($year) must be between -2147483648 and 2147483647
44+
45+
Deprecated: Function intlcal_set() is deprecated since 8.4, use IntlCalendar::set(), IntlCalendar::setDate(), or IntlCalendar::setDateTime() instead in %s on line %d
46+
intlcal_set(): Argument #3 ($month) must be between -2147483648 and 2147483647
47+
48+
Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d
49+
IntlCalendar::set(): Argument #4 ($hour) must be between -2147483648 and 2147483647
50+
51+
Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d
52+
IntlCalendar::set(): Argument #5 ($minute) must be between -2147483648 and 2147483647
53+
54+
Deprecated: Function intlcal_set() is deprecated since 8.4, use IntlCalendar::set(), IntlCalendar::setDate(), or IntlCalendar::setDateTime() instead in %s on line %d
55+
intlcal_set(): Argument #7 ($second) must be between -2147483648 and 2147483647
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
try {
22+
new IntlGregorianCalendar(1, 1, 1, 99999999999, 1);
23+
} catch (Throwable $e) {
24+
echo $e->getMessage(), "\n";
25+
}
26+
27+
try {
28+
new IntlGregorianCalendar(1, 1, 1, 1, 99999999999);
29+
} catch (Throwable $e) {
30+
echo $e->getMessage(), "\n";
31+
}
32+
33+
try {
34+
intlgregcal_create_instance(1, 1, 1, 1, 1, 99999999999);
35+
} catch (Throwable $e) {
36+
echo $e->getMessage(), "\n";
37+
}
38+
?>
39+
--EXPECTF--
40+
Deprecated: Calling IntlGregorianCalendar::__construct() with more than 2 arguments is deprecated, use either IntlGregorianCalendar::createFromDate() or IntlGregorianCalendar::createFromDateTime() instead in %s on line %d
41+
IntlGregorianCalendar::__construct(): Argument #1 ($timezoneOrYear) must be between -2147483648 and 2147483647
42+
43+
Deprecated: Function intlgregcal_create_instance() is deprecated since 8.4, use IntlGregorianCalendar::__construct(), IntlGregorianCalendar::createFromDate(), or IntlGregorianCalendar::createFromDateTime() instead in %s on line %d
44+
intlgregcal_create_instance(): Argument #2 ($localeOrMonth) must be between -2147483648 and 2147483647
45+
46+
Deprecated: Calling IntlGregorianCalendar::__construct() with more than 2 arguments is deprecated, use either IntlGregorianCalendar::createFromDate() or IntlGregorianCalendar::createFromDateTime() instead in %s on line %d
47+
IntlGregorianCalendar::__construct(): Argument #4 ($hour) must be between -2147483648 and 2147483647
48+
49+
Deprecated: Calling IntlGregorianCalendar::__construct() with more than 2 arguments is deprecated, use either IntlGregorianCalendar::createFromDate() or IntlGregorianCalendar::createFromDateTime() instead in %s on line %d
50+
IntlGregorianCalendar::__construct(): Argument #5 ($minute) must be between -2147483648 and 2147483647
51+
52+
Deprecated: Function intlgregcal_create_instance() is deprecated since 8.4, use IntlGregorianCalendar::__construct(), IntlGregorianCalendar::createFromDate(), or IntlGregorianCalendar::createFromDateTime() instead in %s on line %d
53+
intlgregcal_create_instance(): Argument #6 ($second) must be between -2147483648 and 2147483647

0 commit comments

Comments
 (0)