Skip to content
Merged
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
23 changes: 20 additions & 3 deletions ext/intl/converter/converter.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "../intl_error.h"
#include "../intl_common.h"
#include "converter_arginfo.h"
#include "php_intl.h"

typedef struct _php_converter_object {
UConverter *src, *dest;
Expand Down Expand Up @@ -370,7 +371,10 @@ static bool php_converter_set_encoding(php_converter_object *objval,
/* Should never happen */
actual_encoding = "(unknown)";
}
php_error_docref(NULL, E_WARNING, "Ambiguous encoding specified, using %s", actual_encoding);
char *msg;
spprintf(&msg, 0, "Ambiguous encoding specified, using %s", actual_encoding);
intl_error_set(NULL, error, msg);
efree(msg);
} else if (U_FAILURE(error)) {
if (objval) {
THROW_UFAILURE(objval, error);
Expand Down Expand Up @@ -530,10 +534,23 @@ PHP_METHOD(UConverter, __construct) {
Z_PARAM_STRING_OR_NULL(src, src_len)
ZEND_PARSE_PARAMETERS_END();

php_converter_set_encoding(objval, &(objval->src), src, src_len );
php_converter_set_encoding(objval, &(objval->dest), dest, dest_len);
const bool old_use_exception = INTL_G(use_exceptions);
const zend_long old_error_level = INTL_G(error_level);
INTL_G(use_exceptions) = true;
INTL_G(error_level) = 0;
if (UNEXPECTED(!php_converter_set_encoding(objval, &(objval->src), src, src_len))) {
ZEND_ASSERT(EG(exception));
goto cleanup;
}
if (UNEXPECTED(!php_converter_set_encoding(objval, &(objval->dest), dest, dest_len))) {
ZEND_ASSERT(EG(exception));
goto cleanup;
}
php_converter_resolve_callback(&objval->to_cache, Z_OBJ_P(ZEND_THIS), ZEND_STRL("toUCallback"));
php_converter_resolve_callback(&objval->from_cache, Z_OBJ_P(ZEND_THIS), ZEND_STRL("fromUCallback"));
cleanup:
INTL_G(use_exceptions) = old_use_exception;
INTL_G(error_level) = old_error_level;
}
/* }}} */

Expand Down
2 changes: 1 addition & 1 deletion ext/intl/tests/bug75317.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Bug #75317 (UConverter::setDestinationEncoding changes source instead of destinatination)
Bug #75317 (UConverter::setDestinationEncoding changes source instead of destination)
--EXTENSIONS--
intl
--FILE--
Expand Down
23 changes: 15 additions & 8 deletions ext/intl/tests/uconverter___construct_error.phpt
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
--TEST--
Basic UConverter::convert() usage
--INI--
intl.error_level = E_WARNING
--EXTENSIONS--
intl
--FILE--
<?php
$c = new UConverter('utf-8', "\x80");
var_dump($c);
?>
--EXPECTF--
Warning: UConverter::__construct(): returned error 4: U_FILE_ACCESS_ERROR in %s on line %d
object(UConverter)#%d (0) {
try {
$c = new UConverter("\x80", 'utf-8');
var_dump($c);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$c = new UConverter('utf-8', "\x80");
var_dump($c);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
IntlException: UConverter::__construct(): returned error 4: U_FILE_ACCESS_ERROR
IntlException: UConverter::__construct(): returned error 4: U_FILE_ACCESS_ERROR
6 changes: 5 additions & 1 deletion ext/intl/tests/uconverter_bug66873.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ Bug #66873 - crash in UConverter with invalid encoding
intl
--FILE--
<?php
try {
$o = new UConverter(1, 1);
$o->toUCallback(1, 1, 1, $b);
var_dump($o->getErrorCode());
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
int(27)
IntlException: UConverter::__construct(): returned error 4: U_FILE_ACCESS_ERROR