summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/spl/spl_directory.c3
-rw-r--r--ext/spl/tests/bug65545.phpt5
2 files changed, 7 insertions, 1 deletions
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index 668977134e..3fbf2ce12b 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -2865,7 +2865,8 @@ SPL_METHOD(SplFileObject, fread)
Z_STRVAL_P(return_value) = emalloc(length + 1);
Z_STRLEN_P(return_value) = php_stream_read(intern->u.file.stream, Z_STRVAL_P(return_value), length);
- Z_STRVAL_P(return_value)[length] = 0;
+ /* needed because recv/read/gzread doesnt put a null at the end*/
+ Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0;
Z_TYPE_P(return_value) = IS_STRING;
}
diff --git a/ext/spl/tests/bug65545.phpt b/ext/spl/tests/bug65545.phpt
index b43f10f6e6..76c29cbf48 100644
--- a/ext/spl/tests/bug65545.phpt
+++ b/ext/spl/tests/bug65545.phpt
@@ -12,6 +12,10 @@ var_dump($data);
$data = $obj->fread(0);
var_dump($data);
+// read more data than is available
+$data = $obj->fread(filesize(__FILE__) + 32);
+var_dump(strlen($data) === filesize(__FILE__) - 5);
+
?>
--EXPECTF--
string(5) "<?php"
@@ -21,3 +25,4 @@ NULL
Warning: SplFileObject::fread(): Length parameter must be greater than 0 in %s on line %d
bool(false)
+bool(true)