Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GH-17469: UConverter::transcode() not hardcoding error handling. #17488

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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)
Expand Down
11 changes: 7 additions & 4 deletions ext/intl/converter/converter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

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

Should we pass error to the code parameter here? This is exposed via intl_get_error_code() so it can be useful.

In the Ambigious encoding specified case above, if we convert it back to a warning, we could still expose the error code by calling intl_errors_set_code().

Copy link
Member Author

Choose a reason for hiding this comment

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

well objval is null in that case, what do you suggest ?

Copy link
Member

Choose a reason for hiding this comment

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

I was suggesting to pass error to the code parameter, but I'm noticing now that you are already doing exactly that, so please dismiss this comment :D

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;
}
/* }}} */

Expand Down
34 changes: 34 additions & 0 deletions ext/intl/tests/gh17469.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
GH-17469: UConverter::transcode() raises always E_WARNING regardless of INI settings
--SKIPIF--
<?php
if (PHP_OS_FAMILY === "Windows") die("skip currently unsupported on Windows");
?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.use_exceptions", 0);
UConverter::transcode("\x0a", 'nein!!', 'UTF-8');
UConverter::transcode("\x0a", 'UTF-16BE', 'da!');

ini_set("intl.error_level", 0);
ini_set("intl.use_exceptions", 1);

try {
UConverter::transcode("\x0a", 'nein!!', 'UTF-8');
} catch (IntlException $e) {
echo $e->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
Loading