mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
ext/intl: prevent creation of invalid UConverter instance (#19396)
This commit is contained in:
parent
abe75ca850
commit
ca5667bc14
4 changed files with 41 additions and 13 deletions
|
@ -24,6 +24,7 @@
|
||||||
#include "../intl_error.h"
|
#include "../intl_error.h"
|
||||||
#include "../intl_common.h"
|
#include "../intl_common.h"
|
||||||
#include "converter_arginfo.h"
|
#include "converter_arginfo.h"
|
||||||
|
#include "php_intl.h"
|
||||||
|
|
||||||
typedef struct _php_converter_object {
|
typedef struct _php_converter_object {
|
||||||
UConverter *src, *dest;
|
UConverter *src, *dest;
|
||||||
|
@ -370,7 +371,10 @@ static bool php_converter_set_encoding(php_converter_object *objval,
|
||||||
/* Should never happen */
|
/* Should never happen */
|
||||||
actual_encoding = "(unknown)";
|
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)) {
|
} else if (U_FAILURE(error)) {
|
||||||
if (objval) {
|
if (objval) {
|
||||||
THROW_UFAILURE(objval, error);
|
THROW_UFAILURE(objval, error);
|
||||||
|
@ -530,10 +534,23 @@ PHP_METHOD(UConverter, __construct) {
|
||||||
Z_PARAM_STRING_OR_NULL(src, src_len)
|
Z_PARAM_STRING_OR_NULL(src, src_len)
|
||||||
ZEND_PARSE_PARAMETERS_END();
|
ZEND_PARSE_PARAMETERS_END();
|
||||||
|
|
||||||
php_converter_set_encoding(objval, &(objval->src), src, src_len );
|
const bool old_use_exception = INTL_G(use_exceptions);
|
||||||
php_converter_set_encoding(objval, &(objval->dest), dest, dest_len);
|
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->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"));
|
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;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
Bug #75317 (UConverter::setDestinationEncoding changes source instead of destinatination)
|
Bug #75317 (UConverter::setDestinationEncoding changes source instead of destination)
|
||||||
--EXTENSIONS--
|
--EXTENSIONS--
|
||||||
intl
|
intl
|
||||||
--FILE--
|
--FILE--
|
||||||
|
|
|
@ -1,15 +1,22 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
Basic UConverter::convert() usage
|
Basic UConverter::convert() usage
|
||||||
--INI--
|
|
||||||
intl.error_level = E_WARNING
|
|
||||||
--EXTENSIONS--
|
--EXTENSIONS--
|
||||||
intl
|
intl
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
$c = new UConverter('utf-8', "\x80");
|
try {
|
||||||
var_dump($c);
|
$c = new UConverter("\x80", 'utf-8');
|
||||||
?>
|
var_dump($c);
|
||||||
--EXPECTF--
|
} catch (Throwable $e) {
|
||||||
Warning: UConverter::__construct(): returned error 4: U_FILE_ACCESS_ERROR in %s on line %d
|
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||||
object(UConverter)#%d (0) {
|
|
||||||
}
|
}
|
||||||
|
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
|
||||||
|
|
|
@ -4,9 +4,13 @@ Bug #66873 - crash in UConverter with invalid encoding
|
||||||
intl
|
intl
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
|
try {
|
||||||
$o = new UConverter(1, 1);
|
$o = new UConverter(1, 1);
|
||||||
$o->toUCallback(1, 1, 1, $b);
|
$o->toUCallback(1, 1, 1, $b);
|
||||||
var_dump($o->getErrorCode());
|
var_dump($o->getErrorCode());
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
int(27)
|
IntlException: UConverter::__construct(): returned error 4: U_FILE_ACCESS_ERROR
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue