mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Fix GH-20833: mb_str_pad() divide by zero if padding string is invalid in the encoding
If the padding string is not valid in the given encoding, mb_get_strlen() can return 0. Closes GH-20834.
This commit is contained in:
4
NEWS
4
NEWS
@@ -2,6 +2,10 @@ PHP NEWS
|
|||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
?? ??? ????, PHP 8.4.18
|
?? ??? ????, PHP 8.4.18
|
||||||
|
|
||||||
|
- MbString:
|
||||||
|
. Fixed bug GH-20833 (mb_str_pad() divide by zero if padding string is
|
||||||
|
invalid in the encoding). (ndossche)
|
||||||
|
|
||||||
- Readline:
|
- Readline:
|
||||||
. Fixed bug GH-18139 (Memory leak when overriding some settings
|
. Fixed bug GH-18139 (Memory leak when overriding some settings
|
||||||
via readline_info()). (ndossche)
|
via readline_info()). (ndossche)
|
||||||
|
|||||||
@@ -5848,6 +5848,11 @@ PHP_FUNCTION(mb_str_pad)
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t pad_length = mb_get_strlen(pad, encoding);
|
size_t pad_length = mb_get_strlen(pad, encoding);
|
||||||
|
if (pad_length == 0) {
|
||||||
|
/* Possible with invalidly encoded padding string. */
|
||||||
|
zend_argument_must_not_be_empty_error(3);
|
||||||
|
RETURN_THROWS();
|
||||||
|
}
|
||||||
|
|
||||||
size_t num_mb_pad_chars = pad_to_length - input_length;
|
size_t num_mb_pad_chars = pad_to_length - input_length;
|
||||||
|
|
||||||
|
|||||||
16
ext/mbstring/tests/gh20833.phpt
Normal file
16
ext/mbstring/tests/gh20833.phpt
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
--TEST--
|
||||||
|
GH-20833 (mb_str_pad() divide by zero if padding string is invalid in the encoding)
|
||||||
|
--EXTENSIONS--
|
||||||
|
mbstring
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$utf8 = "test";
|
||||||
|
$utf32 = mb_convert_encoding($utf8, 'UTF-32', 'UTF-8');
|
||||||
|
try {
|
||||||
|
mb_str_pad($utf32, 5, "1" /* invalid for encoding */, STR_PAD_RIGHT, "UTF-32");
|
||||||
|
} catch (ValueError $e) {
|
||||||
|
echo $e::class, ": ", $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
ValueError: mb_str_pad(): Argument #3 ($pad_string) must not be empty
|
||||||
Reference in New Issue
Block a user