Skip to content

ext/Intl: Fix out-of-bounds argument positions in calendar date/time APIs#22044

Open
LamentXU123 wants to merge 1 commit into
php:PHP-8.4from
LamentXU123:bug-fix-13
Open

ext/Intl: Fix out-of-bounds argument positions in calendar date/time APIs#22044
LamentXU123 wants to merge 1 commit into
php:PHP-8.4from
LamentXU123:bug-fix-13

Conversation

@LamentXU123
Copy link
Copy Markdown
Contributor

@LamentXU123 LamentXU123 commented May 15, 2026

When I was looking at the new deprecation of IntlGregorianCalendar::__construct() with more than 2 arguments is deprecated, I find that the argument position in the overflow error is actually wrong. That is

<?php
try {
    new IntlGregorianCalendar(99999999999, 1, 1);
} catch (Throwable $e) {
    echo $e->getMessage(), "\n";
}

Will result in

Deprecated: Calling IntlGregorianCalendar::__construct() with more than 2 arguments is deprecated, use either IntlGregorianCalendar::createFromDate() or IntlGregorianCalendar::createFromDateTime() instead in /in/dB6p5 on line 3
IntlGregorianCalendar::__construct(): Argument #-1 must be between -2147483648 and 2147483647

Which I expected the last line being

IntlGregorianCalendar::__construct(): Argument #1 must be between -2147483648 and 2147483647

Seems like in the case we don't need to use hasThis() because $this is impossible to exist. Just using i+1 here will be safe enough.

Edited: With further research, IntlCalendar::set also has this problem.

<?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

@devnexen
Copy link
Copy Markdown
Member

the bug is legit it seems I ll look at it shortly.

Copy link
Copy Markdown
Member

@devnexen devnexen left a comment

Choose a reason for hiding this comment

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

just the PR title misses a space after IntlGregorianCalendar

@LamentXU123 LamentXU123 changed the title ext/Intl: Fix out-of-bounds argument positions for IntlGregorianCalendardate/time construction ext/Intl: Fix out-of-bounds argument positions for IntlGregorianCalendar date/time construction May 15, 2026
@LamentXU123
Copy link
Copy Markdown
Contributor Author

LamentXU123 commented May 15, 2026

Uh after a quick scan I actually doubt that similar issues exists across the intl code base. Will take a look later and deal it in another PR if any. I already find one in IntlCalendar::set(). Just give me a sec I will add it into this PR.

@LamentXU123 LamentXU123 changed the title ext/Intl: Fix out-of-bounds argument positions for IntlGregorianCalendar date/time construction ext/Intl: Fix out-of-bounds argument positions in calendar date/time APIs May 15, 2026
@devnexen
Copy link
Copy Markdown
Member

this is fine I did not plan to merge before this week end anyway.

}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants