From a1d1269688e8e493eb472d5b6d12b8f661f10686 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Thu, 16 Jan 2025 19:03:06 +0000 Subject: [PATCH] Fix GH-17469: UConverter::transcode() not hardcoding error handling. Respecting instead intl.use_exceptions/intl.error_level. close GH-17488 --- NEWS | 2 ++ ext/intl/converter/converter.c | 11 +++++++---- ext/intl/tests/gh17469.phpt | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 ext/intl/tests/gh17469.phpt diff --git a/NEWS b/NEWS index 0c67da4eba016..a7db6d9f3002d 100644 --- a/NEWS +++ b/NEWS @@ -33,6 +33,8 @@ PHP NEWS - Intl: . Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos) + . Fixed bug GH-17469 (UConverter::transcode always emit E_WARNING on + invalid encoding). (David Carlier) - Opcache: . Fixed bug GH-17307 (Internal closure causes JIT failure). (nielsdos) diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.c index 6f65cfc2eea69..75fbfbc8e8861 100644 --- a/ext/intl/converter/converter.c +++ b/ext/intl/converter/converter.c @@ -381,20 +381,23 @@ static bool php_converter_set_encoding(php_converter_object *objval, if (objval) { THROW_UFAILURE(objval, "ucnv_open", error); } else { - php_error_docref(NULL, E_WARNING, "Error setting encoding: %d - %s", (int)error, u_errorName(error)); + char *msg; + spprintf(&msg, 0, "Error setting encoding: %d - %s", (int)error, u_errorName(error)); + intl_error_set(NULL, error, msg, 1); + efree(msg); } - return 0; + return false; } if (objval && !php_converter_set_callbacks(objval, cnv)) { - return 0; + return false; } if (*pcnv) { ucnv_close(*pcnv); } *pcnv = cnv; - return 1; + return true; } /* }}} */ diff --git a/ext/intl/tests/gh17469.phpt b/ext/intl/tests/gh17469.phpt new file mode 100644 index 0000000000000..a0c5d719817d7 --- /dev/null +++ b/ext/intl/tests/gh17469.phpt @@ -0,0 +1,34 @@ +--TEST-- +GH-17469: UConverter::transcode() raises always E_WARNING regardless of INI settings +--SKIPIF-- + +--FILE-- +getMessage(), PHP_EOL; +} +try { + UConverter::transcode("\x0a", 'UTF-16BE', 'da!'); +} catch (IntlException $e) { + echo $e->getMessage(), PHP_EOL; +} +?> +--EXPECTF-- + +Warning: UConverter::transcode(): Error setting encoding: 4 - U_FILE_ACCESS_ERROR in %s on line %d + +Warning: UConverter::transcode(): Error setting encoding: 4 - U_FILE_ACCESS_ERROR in %s on line 5 +Error setting encoding: 4 - U_FILE_ACCESS_ERROR +Error setting encoding: 4 - U_FILE_ACCESS_ERROR