Skip to content

Commit 252bc44

Browse files
adamjseitzcmb69
authored andcommitted
Fix #80384: limit read buffer size
In the case of a stream with no filters, php_stream_fill_read_buffer only reads stream->chunk_size into the read buffer. If the stream has filters attached, it could unnecessarily buffer a large amount of data. With this change, php_stream_fill_read_buffer only proceeds until either the requested size or stream->chunk_size is available in the read buffer.
1 parent 315f3f8 commit 252bc44

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

main/streams/streams.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,15 @@ PHPAPI int _php_stream_fill_read_buffer(php_stream *stream, size_t size)
542542
/* allocate/fill the buffer */
543543

544544
if (stream->readfilters.head) {
545+
size_t to_read_now = MIN(size, stream->chunk_size);
545546
char *chunk_buf;
546547
php_stream_bucket_brigade brig_in = { NULL, NULL }, brig_out = { NULL, NULL };
547548
php_stream_bucket_brigade *brig_inp = &brig_in, *brig_outp = &brig_out, *brig_swap;
548549

549550
/* allocate a buffer for reading chunks */
550551
chunk_buf = emalloc(stream->chunk_size);
551552

552-
while (!stream->eof && (stream->writepos - stream->readpos < (zend_off_t)size)) {
553+
while (!stream->eof && (stream->writepos - stream->readpos < (zend_off_t)to_read_now)) {
553554
ssize_t justread = 0;
554555
int flags;
555556
php_stream_bucket *bucket;

0 commit comments

Comments
 (0)