Remove 'bogus' error condition in str_pad()

This commit is contained in:
George Peter Banyard 2019-08-23 20:27:50 +02:00
parent 675e975185
commit 9d18f23c4c
3 changed files with 37 additions and 6 deletions

View File

@ -5697,11 +5697,6 @@ PHP_FUNCTION(str_pad)
}
num_pad_chars = pad_length - ZSTR_LEN(input);
if (num_pad_chars >= INT_MAX) {
php_error_docref(NULL, E_WARNING, "Padding length is too long");
return;
}
result = zend_string_safe_alloc(1, ZSTR_LEN(input), num_pad_chars, 0);
ZSTR_LEN(result) = 0;

View File

@ -0,0 +1,36 @@
--TEST--
Test str_pad() function : usage variations - large values for '$pad_length' argument
--FILE--
<?php
/* Prototype : string str_pad ( string $input , int $pad_length [, string $pad_string [, int $pad_type ]] )
* Description: Pad a string to a certain length with another string
* Source code: ext/standard/string.c
*/
/* Test str_pad() function: with unexpected inputs for '$pad_length'
* and expected type for '$input'
*/
echo "*** Testing str_pad() function: with large value for for 'pad_length' argument ***\n";
//defining '$input' argument
$input = "Test string";
$extra_large_pad_length = PHP_INT_MAX*5;
try {
var_dump( str_pad($input, $extra_large_pad_length) );
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}
$php_int_max_pad_length = PHP_INT_MAX;
var_dump( str_pad($input, $php_int_max_pad_length) );
?>
--EXPECTF--
*** Testing str_pad() function: with large value for for 'pad_length' argument ***
str_pad() expects parameter 2 to be int, float given
Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d

View File

@ -31,4 +31,4 @@ var_dump( str_pad($input, $pad_length) );
--EXPECTF--
*** Testing str_pad() function: with large value for for 'pad_length' argument ***
Fatal error: Allowed memory size of 134217728 bytes exhausted%s(tried to allocate %d bytes) in %s on line %d
Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d