diff options
author | Arnaud Le Blanc <lbarnaud@php.net> | 2008-11-03 23:29:50 +0000 |
---|---|---|
committer | Arnaud Le Blanc <lbarnaud@php.net> | 2008-11-03 23:29:50 +0000 |
commit | c644ba688b6a798cc48d166430a71c7ada4d558c (patch) | |
tree | a3b78d4a5e7837339e73b89e1b8f639c8e0b7116 | |
parent | 07fe6986ccdf789009233a55cb00062a10d0b744 (diff) | |
download | php-git-c644ba688b6a798cc48d166430a71c7ada4d558c.tar.gz |
MFH: Fixed bug #44607 (stream_get_line unable to correctly identify the
"ending" in the stream content)
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | ext/standard/tests/file/bug44607.phpt | 22 | ||||
-rwxr-xr-x | main/streams/streams.c | 22 |
3 files changed, 37 insertions, 9 deletions
@@ -26,6 +26,8 @@ PHP NEWS (Arnaud) - Fixed bug #44938 (gettext functions crash with overly long domain). (Christian Schneider, Ilia) +- Fixed bug #44607 (stream_get_line unable to correctly identify the "ending" + in the stream content). (Arnaud) - Fixed bug #44327 (PDORow::queryString property & numeric offsets / Crash). (Felipe) - Fixed bug #43452 (strings containing a weekday, or a number plus weekday diff --git a/ext/standard/tests/file/bug44607.phpt b/ext/standard/tests/file/bug44607.phpt new file mode 100644 index 0000000000..9eb6d5fcba --- /dev/null +++ b/ext/standard/tests/file/bug44607.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #44607 (stream_get_line unable to correctly identify the "ending" in the stream content) +--FILE-- +<?php +$eol = '<EOL>'; +$tempnam = tempnam(sys_get_temp_dir(), 'php'); +$data = str_repeat('.', 14000); +$data .= $eol; +$data .= $data; +file_put_contents($tempnam, $data); +$fd = fopen($tempnam, 'r'); +var_dump(strlen(stream_get_line($fd, 15000, $eol))); +var_dump(strlen(stream_get_line($fd, 15000, $eol))); +fseek($fd, 1, SEEK_SET); +var_dump(strlen(stream_get_line($fd, 15000, $eol))); +var_dump(strlen(stream_get_line($fd, 15000, $eol))); +?> +--EXPECT-- +int(14000) +int(14000) +int(13999) +int(14000) diff --git a/main/streams/streams.c b/main/streams/streams.c index e3add158dd..a5f99791d8 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -531,16 +531,16 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D efree(chunk_buf); } else { + /* reduce buffer memory consumption if possible, to avoid a realloc */ + if (stream->readbuf && stream->readbuflen - stream->writepos < stream->chunk_size) { + memmove(stream->readbuf, stream->readbuf + stream->readpos, stream->readbuflen - stream->readpos); + stream->writepos -= stream->readpos; + stream->readpos = 0; + } /* is there enough data in the buffer ? */ - if (stream->writepos - stream->readpos < (off_t)size) { + while (stream->writepos - stream->readpos < (off_t)size) { size_t justread = 0; - - /* reduce buffer memory consumption if possible, to avoid a realloc */ - if (stream->readbuf && stream->readbuflen - stream->writepos < stream->chunk_size) { - memmove(stream->readbuf, stream->readbuf + stream->readpos, stream->readbuflen - stream->readpos); - stream->writepos -= stream->readpos; - stream->readpos = 0; - } + size_t toread; /* grow the buffer if required * TODO: this can fail for persistent streams */ @@ -550,13 +550,17 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D stream->is_persistent); } + toread = stream->readbuflen - stream->writepos; justread = stream->ops->read(stream, stream->readbuf + stream->writepos, - stream->readbuflen - stream->writepos + toread TSRMLS_CC); if (justread != (size_t)-1) { stream->writepos += justread; } + if (stream->eof || justread != toread) { + break; + } } } } |