From 9ebdb491cc598e1fa55bf73cf18d6841097c7ffa Mon Sep 17 00:00:00 2001 From: hohphu8 Date: Sun, 29 Nov 2026 00:14:13 +0700 Subject: [PATCH] Fix NULL pointer dereference in intl_datetime_decompose() --- ext/intl/common/common_date.cpp | 10 +++++- ...ormat_uninitialized_datetime_subclass.phpt | 33 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 ext/intl/tests/dateformat_uninitialized_datetime_subclass.phpt diff --git a/ext/intl/common/common_date.cpp b/ext/intl/common/common_date.cpp index a412ddcdffcd..a635a4f18816 100644 --- a/ext/intl/common/common_date.cpp +++ b/ext/intl/common/common_date.cpp @@ -128,9 +128,17 @@ U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz, return FAILURE; } + zval_ptr_dtor(&zfuncname); datetime = Z_PHPDATE_P(z); + if (!datetime->time) { + spprintf(&message, 0, "%s: the %s object is not properly " + "initialized", func, ZSTR_VAL(Z_OBJCE_P(z)->name)); + intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, + message, 1); + efree(message); + return FAILURE; + } *millis = U_MILLIS_PER_SECOND * (double)Z_LVAL(retval) + (datetime->time->us / 1000); - zval_ptr_dtor(&zfuncname); } if (tz) { diff --git a/ext/intl/tests/dateformat_uninitialized_datetime_subclass.phpt b/ext/intl/tests/dateformat_uninitialized_datetime_subclass.phpt new file mode 100644 index 000000000000..fb0e728e4870 --- /dev/null +++ b/ext/intl/tests/dateformat_uninitialized_datetime_subclass.phpt @@ -0,0 +1,33 @@ +--TEST-- +intl_datetime_decompose() rejects uninitialized DateTime subclass overriding getTimestamp() +--EXTENSIONS-- +intl +--FILE-- +format($dt)); +var_dump($fmt->getErrorMessage()); + +var_dump(MessageFormatter::formatMessage('en_US', '{0,date,short}', [$dt])); +var_dump(intl_get_error_message()); +?> +--EXPECTF-- +bool(false) +string(%d) "%sthe UninitDateTime object is not properly initialized: U_ILLEGAL_ARGUMENT_ERROR" +bool(false) +string(%d) "%sthe UninitDateTime object is not properly initialized: U_ILLEGAL_ARGUMENT_ERROR" +bool(false) +string(83) "The argument for key '0' cannot be used as a date or time: U_ILLEGAL_ARGUMENT_ERROR"