1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

ext/mbstring: Check conversion map only has integers

This commit is contained in:
Gina Peter Banyard
2023-12-06 23:47:00 +00:00
parent 193b22fa2b
commit e74bf42c81
6 changed files with 58 additions and 17 deletions

View File

@@ -31,6 +31,10 @@ PHP 8.4 UPGRADE NOTES
will not affect you. As a result DOMImplementation::createDocument() now has
a tentative return type of DOMDocument instead of DOMDocument|false.
- MBString:
. mb_encode_numericentity() and mb_decode_numericentity() now check that
the $map is only composed of integers, if not a ValueError is thrown.
- PDO_DBLIB:
. setAttribute, DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER and DBLIB_ATTR_DATETIME_CONVERT
have been changed to set value as a bool.

View File

@@ -3878,7 +3878,14 @@ static uint32_t *make_conversion_map(HashTable *target_hash, size_t *conversion_
uint32_t *mapelm = convmap;
ZEND_HASH_FOREACH_VAL(target_hash, hash_entry) {
*mapelm++ = zval_get_long(hash_entry);
bool failed = true;
zend_long tmp = zval_try_get_long(hash_entry, &failed);
if (failed) {
efree(convmap);
zend_argument_value_error(2, "must only be composed of values of type int");
return NULL;
}
*mapelm++ = tmp;
} ZEND_HASH_FOREACH_END();
return convmap;

View File

@@ -61,13 +61,6 @@ echo "12: " . bin2hex(mb_decode_numericentity(mb_convert_encoding('�',
$convmap = [];
echo "13: " . mb_decode_numericentity('föo', $convmap, "UTF-8") . "\n";
$convmap = array(0x0, 0x2FFFF, 0); // 3 elements
try {
echo "14: " . mb_decode_numericentity($str3, $convmap, "UTF-8") . "\n";
} catch (ValueError $ex) {
echo "14: " . $ex->getMessage()."\n";
}
echo "15: " . bin2hex(mb_decode_numericentity('�', [0, 1, 0, 0xFFFF], 'UTF-8')) . "\n";
echo "16: " . bin2hex(mb_decode_numericentity('�', [0, 1, 0, 0xFFFF], 'UTF-8')) . "\n";
@@ -182,7 +175,6 @@ for ($i = 12; $i < 256; $i++) {
11e: &#x000000000
12: 00bc614e
13: f&ouml;o
14: mb_decode_numericentity(): Argument #2 ($map) must have a multiple of 4 elements
15: 00
16: 00
17: föo

View File

@@ -0,0 +1,23 @@
--TEST--
mb_decode_numericentity() map errors
--EXTENSIONS--
mbstring
--FILE--
<?php
try {
$convmap = array(0xFF, 0x2FFFF, 0); // 3 elements
echo mb_decode_numericentity('str', $convmap, "UTF-8") . "\n";
} catch (ValueError $ex) {
echo $ex->getMessage(), "\n";
}
try {
$convmap = array(0xFF, "not an int", 0, 0); // 3 elements
echo mb_decode_numericentity('str', $convmap, "UTF-8") . "\n";
} catch (ValueError $ex) {
echo $ex->getMessage(), "\n";
}
?>
--EXPECT--
mb_decode_numericentity(): Argument #2 ($map) must have a multiple of 4 elements
mb_decode_numericentity(): Argument #2 ($map) must only be composed of values of type int

View File

@@ -17,13 +17,6 @@ echo "3: " . mb_encode_numericentity('aŒbœcŠdše€fg', $convmap, "UTF-8") .
$convmap = [];
echo "4: " . mb_encode_numericentity('föo', $convmap, "UTF-8") . "\n";
try {
$convmap = array(0xFF, 0x2FFFF, 0); // 3 elements
echo "5: " . mb_encode_numericentity('aŒbœcŠdše€fg', $convmap, "UTF-8") . "\n";
} catch (ValueError $ex) {
echo "5: " . $ex->getMessage() . "\n";
}
// HTML-encode a null byte
echo "6: " . mb_encode_numericentity("\x00", array(0, 1, 0, 0xFFFF), "UTF-8", false) . "\n";
echo "6 (hex): " . mb_encode_numericentity("\x00", array(0, 1, 0, 0xFFFF), "UTF-8", true) . "\n";
@@ -72,7 +65,6 @@ echo "13: " . mb_encode_numericentity("\xFF", $convmap, "ASCII", true) . "\n";
2: &#402;&#913;&#914;&#915;&#916;&#917;&#918;&#919;&#920;&#921;&#922;&#923;&#924;&#925;&#926;&#927;&#928;&#929;&#931;&#932;&#933;&#934;&#935;&#936;&#937;&#945;&#946;&#947;&#948;&#949;&#950;&#951;&#952;&#953;&#954;&#955;&#956;&#957;&#958;&#959;&#960;&#961;&#962;&#963;&#964;&#965;&#966;&#967;&#968;&#969;&#977;&#978;&#982;&#8226;&#8230;&#8242;&#8243;&#8254;&#8260;&#8472;&#8465;&#8476;&#8482;&#8501;&#8592;&#8593;&#8594;&#8595;&#8596;&#8629;&#8656;&#8657;&#8658;&#8659;&#8660;&#8704;&#8706;&#8707;&#8709;&#8711;&#8712;&#8713;&#8715;&#8719;&#8721;&#8722;&#8727;&#8730;&#8733;&#8734;&#8736;&#8743;&#8744;&#8745;&#8746;&#8747;&#8756;&#8764;&#8773;&#8776;&#8800;&#8801;&#8804;&#8805;&#8834;&#8835;&#8836;&#8838;&#8839;&#8853;&#8855;&#8869;&#8901;&#8968;&#8969;&#8970;&#8971;&#9001;&#9002;&#9674;&#9824;&#9827;&#9829;&#9830;
3: a&#338;b&#339;c&#352;d&#353;e&#8364;fg
4: föo
5: mb_encode_numericentity(): Argument #2 ($map) must have a multiple of 4 elements
6: &#0;
6 (hex): &#x0;
7: föo

View File

@@ -0,0 +1,23 @@
--TEST--
mb_encode_numericentity() map errors
--EXTENSIONS--
mbstring
--FILE--
<?php
try {
$convmap = array(0xFF, 0x2FFFF, 0); // 3 elements
echo mb_encode_numericentity('str', $convmap, "UTF-8") . "\n";
} catch (ValueError $ex) {
echo $ex->getMessage(), "\n";
}
try {
$convmap = array(0xFF, "not an int", 0, 0); // 3 elements
echo mb_encode_numericentity('str', $convmap, "UTF-8") . "\n";
} catch (ValueError $ex) {
echo $ex->getMessage(), "\n";
}
?>
--EXPECT--
mb_encode_numericentity(): Argument #2 ($map) must have a multiple of 4 elements
mb_encode_numericentity(): Argument #2 ($map) must only be composed of values of type int