summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2017-11-13 06:11:59 -0500
committerRemi Collet <remi@php.net>2017-11-15 15:31:09 +0100
commit96016087a4a97f587710640ee3cdf7e41fac997f (patch)
tree4576349ec912cdb891a37dd9c238f8f8c12e7ebc
parentcaa630a7fe8fb6cb0905a4b77b497cbc90f9a5bc (diff)
downloadphp-git-96016087a4a97f587710640ee3cdf7e41fac997f.tar.gz
Bugfix#75515 php://streams behaving greedily
5060fc23 attempted to fix #68948 by treating all non-uri streams as non-blocking, however php://fd/* streams (which includes stdin) may block if the other end of the IPC isn't finished. This represents a partial revert to the pre RC6 state, but includes an escape hatch for php://memory and php://temp streams which are local to the current process. This also restores stream_set_chunk_size test to previous state.
-rw-r--r--ext/standard/tests/streams/stream_set_chunk_size.phpt10
-rw-r--r--main/streams/streams.c7
2 files changed, 9 insertions, 8 deletions
diff --git a/ext/standard/tests/streams/stream_set_chunk_size.phpt b/ext/standard/tests/streams/stream_set_chunk_size.phpt
index 88f4897e93..ce272519c4 100644
--- a/ext/standard/tests/streams/stream_set_chunk_size.phpt
+++ b/ext/standard/tests/streams/stream_set_chunk_size.phpt
@@ -39,7 +39,7 @@ var_dump(fwrite($f, str_repeat('b', 3)));
echo "should return previous chunk size (1)\n";
var_dump(stream_set_chunk_size($f, 100));
-echo "should elicit 3 reads of size 100 (chunk size)\n";
+echo "should elicit one read of size 100 (chunk size)\n";
var_dump(strlen(fread($f, 250)));
echo "should elicit one read of size 100 (chunk size)\n";
var_dump(strlen(fread($f, 50)));
@@ -67,15 +67,13 @@ write with size: 1
int(3)
should return previous chunk size (1)
int(1)
-should elicit 3 reads of size 100 (chunk size)
-read with size: 100
-read with size: 100
+should elicit one read of size 100 (chunk size)
read with size: 100
-int(250)
+int(100)
should elicit one read of size 100 (chunk size)
+read with size: 100
int(50)
should elicit no read because there is sufficient cached data
-read with size: 100
int(50)
should elicit 2 writes of size 100 and one of size 50
write with size: 100
diff --git a/main/streams/streams.c b/main/streams/streams.c
index b1099b6fcc..19d08c7978 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -24,6 +24,7 @@
#define _GNU_SOURCE
#include "php.h"
#include "php_globals.h"
+#include "php_memory_streams.h"
#include "php_network.h"
#include "php_open_temporary_file.h"
#include "ext/standard/file.h"
@@ -709,8 +710,10 @@ PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size)
break;
}
- /* just break anyway, to avoid greedy read */
- if (!stream->wrapper || stream->wrapper->is_url) {
+ /* just break anyway, to avoid greedy read for file://, php://memory, and php://temp */
+ if ((stream->wrapper != &php_plain_files_wrapper) &&
+ (stream->ops != &php_stream_memory_ops) &&
+ (stream->ops != &php_stream_temp_ops)) {
break;
}
}