]> granicus.if.org Git - php/commitdiff
Fix Bug #23770: Odd output from file_get_contents().
authorWez Furlong <wez@php.net>
Fri, 23 May 2003 11:10:34 +0000 (11:10 +0000)
committerWez Furlong <wez@php.net>
Fri, 23 May 2003 11:10:34 +0000 (11:10 +0000)
php_stream_copy_to_mem couldn't handle the case when the read returned less
than chunk_size/4 bytes (except when it was the last chunk read).

main/streams.c

index 4d68335eae6b4ce769fbf720c38b9cbced931603..62b77b79b46446d425e6f4bf0ec3c9dc0c153ca2 100755 (executable)
@@ -545,10 +545,10 @@ PHPAPI php_stream_filter *php_stream_filter_remove(php_stream *stream, php_strea
 static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_DC)
 {
        /* allocate/fill the buffer */
-       
+       size_t justread = 0;
+
        /* is there enough data in the buffer ? */
        if (stream->writepos - stream->readpos < (off_t)size) {
-               size_t justread = 0;
        
                /* ignore eof here; the underlying state might have changed */
                
@@ -583,13 +583,12 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
                        stream->writepos += justread;
                }
        }
-
 }
 
 PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size TSRMLS_DC)
 {
        size_t toread = 0, didread = 0;
-       
+
        while (size > 0) {
 
                /* take from the read buffer first.
@@ -1185,13 +1184,15 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen
        }
  
        ptr = *buf = pemalloc_rel_orig(max_len, persistent);
+
        while((ret = php_stream_read(src, ptr, max_len - len))) {
                len += ret;
                if (len + min_room >= max_len) {
                        *buf = perealloc_rel_orig(*buf, max_len + step, persistent);
                        max_len += step;
                        ptr = *buf + len;
+               } else {
+                       ptr += ret;
                }
        }
        if (len) {