Skip to content

Fix NULL pointer dereference in intl_datetime_decompose() for uninitialized DateTime subclass - #25878

Closed
hohphu8 wants to merge 1 commit into
php:PHP-8.4from
hohphu8:fix-intl-datetime-decompose-uninit
Closed

hohphu8 wants to merge 1 commit into
php:PHP-8.4from
hohphu8:fix-intl-datetime-decompose-uninit

Conversation

@hohphu8

@hohphu8 hohphu8 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

In intl_datetime_decompose() (ext/intl/common/common_date.cpp), the if (millis) block dereferences datetime->time->us without checking whether datetime->time is initialized (unlike the if (tz) block immediately below it). A DateTime subclass that skips parent::__construct() and overrides getTimestamp() to return an int causes a NULL pointer dereference when passed to IntlDateFormatter::formatObject() or IntlDateFormatter::format().

Check if (!datetime->time) before accessing datetime->time->us and report U_ILLEGAL_ARGUMENT_ERROR consistently with the if (tz) branch, while preserving existing getTimestamp() error behavior for subclasses that do not override it.

Added a regression test covering both IntlDateFormatter::formatObject() and IntlDateFormatter::format().

Note: AI-assisted code audit; manually verified and reproduced locally.

@devnexen

devnexen commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

The fix is looking good, however can you add a test case with MessageFormatter::formatMessage() ?

@hohphu8
hohphu8 force-pushed the fix-intl-datetime-decompose-uninit branch from 4dcfc6f to 9ebdb49 Compare November 28, 2026 17:39
@hohphu8

hohphu8 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Added a MessageFormatter::formatMessage() test case as requested, thanks!

@LamentXU123 LamentXU123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I will add a NEWS entry when merging.

Might have some trouble merging upwards but I can handle it.

LamentXU123 added a commit that referenced this pull request Nov 28, 2026
* PHP-8.6:
  ext/intl: Fix crash when formatting an uninitialized DateTime (#25878)
@LamentXU123

Copy link
Copy Markdown
Member

Thanks to LLMs we can scan and fix these stupid bugs <(_ _)>.

opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-php__php-src that referenced this pull request Nov 28, 2026
* PHP-8.4:
  ext/intl: Fix crash when formatting an uninitialized DateTime (php#25878)
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-php__php-src that referenced this pull request Nov 28, 2026
* PHP-8.5:
  ext/intl: Fix crash when formatting an uninitialized DateTime (php#25878)
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.

3 participants