Skip to content

Commit 0a45e8f

Browse files
committed
Bugfix#75515 php://streams behaving greedily
5060fc2 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.
1 parent 704bcd3 commit 0a45e8f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

ext/standard/tests/streams/stream_set_chunk_size.phpt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var_dump(fwrite($f, str_repeat('b', 3)));
3939

4040
echo "should return previous chunk size (1)\n";
4141
var_dump(stream_set_chunk_size($f, 100));
42-
echo "should elicit 3 reads of size 100 (chunk size)\n";
42+
echo "should elicit one read of size 100 (chunk size)\n";
4343
var_dump(strlen(fread($f, 250)));
4444
echo "should elicit one read of size 100 (chunk size)\n";
4545
var_dump(strlen(fread($f, 50)));
@@ -67,15 +67,13 @@ write with size: 1
6767
int(3)
6868
should return previous chunk size (1)
6969
int(1)
70-
should elicit 3 reads of size 100 (chunk size)
71-
read with size: 100
72-
read with size: 100
70+
should elicit one read of size 100 (chunk size)
7371
read with size: 100
74-
int(250)
72+
int(100)
7573
should elicit one read of size 100 (chunk size)
74+
read with size: 100
7675
int(50)
7776
should elicit no read because there is sufficient cached data
78-
read with size: 100
7977
int(50)
8078
should elicit 2 writes of size 100 and one of size 50
8179
write with size: 100

main/streams/streams.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define _GNU_SOURCE
2525
#include "php.h"
2626
#include "php_globals.h"
27+
#include "php_memory_streams.h"
2728
#include "php_network.h"
2829
#include "php_open_temporary_file.h"
2930
#include "ext/standard/file.h"
@@ -709,8 +710,10 @@ PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size)
709710
break;
710711
}
711712

712-
/* just break anyway, to avoid greedy read */
713-
if (!stream->wrapper || stream->wrapper->is_url) {
713+
/* just break anyway, to avoid greedy read for file://, php://memory, and php://temp */
714+
if ((stream->wrapper != &php_plain_files_wrapper) &&
715+
(stream->ops != &php_stream_memory_ops) &&
716+
(stream->ops != &php_stream_temp_ops)) {
714717
break;
715718
}
716719
}

0 commit comments

Comments
 (0)