Skip to content

Commit fd463cf

Browse files
committed
Merge branch 'PHP-7.2'
* PHP-7.2: Bugfix#75515 php://streams behaving greedily
2 parents bdf77f0 + 0a45e8f commit fd463cf

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"
@@ -704,8 +705,10 @@ PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size)
704705
break;
705706
}
706707

707-
/* just break anyway, to avoid greedy read */
708-
if (!stream->wrapper || stream->wrapper->is_url) {
708+
/* just break anyway, to avoid greedy read for file://, php://memory, and php://temp */
709+
if ((stream->wrapper != &php_plain_files_wrapper) &&
710+
(stream->ops != &php_stream_memory_ops) &&
711+
(stream->ops != &php_stream_temp_ops)) {
709712
break;
710713
}
711714
}

0 commit comments

Comments
 (0)