mirror of
https://github.com/php/php-src.git
synced 2026-03-28 18:22:42 +01:00
Merge branch 'PHP-7.4'
* PHP-7.4: Require non-negative length in stream_get_contents()
This commit is contained in:
@@ -419,6 +419,11 @@ PHP_FUNCTION(stream_get_contents)
|
||||
Z_PARAM_LONG(desiredpos)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
if (maxlen < 0 && maxlen != PHP_STREAM_COPY_ALL) {
|
||||
php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to zero, or -1");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
php_stream_from_zval(stream, zsrc);
|
||||
|
||||
if (desiredpos >= 0) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
stream_get_contents() with negative max length
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tmp = tmpfile();
|
||||
fwrite($tmp, "abcd");
|
||||
var_dump(stream_get_contents($tmp, 2, 1));
|
||||
var_dump(stream_get_contents($tmp, -2));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
string(2) "bc"
|
||||
|
||||
Warning: stream_get_contents(): Length must be greater than or equal to zero, or -1 in %s on line %d
|
||||
bool(false)
|
||||
Reference in New Issue
Block a user