cataphract                               Thu, 14 Oct 2010 02:03:18 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=304380

Log:
- [DOC] Changed stream_get_contents() so that the offset is relative to the
  current position (seek with SEEK_CUR, not SEEK_SET). Only positive values are
  allowed. This breaking change is necessary to fix the erratic behavior in
  streams without a seek handlder. Addresses bug #53006.
#Note that the example on the doc page for stream_get_contents() may fail
#without this change.
#This change is also in the spirit of stream_get_contents(), whose description
#is "Reads all remaining bytes (or up to maxlen bytes) from a stream...".
#Previous behavior allowed setting the file pointer to positions before the
#current one, so they wouldn't be "remaining bytes". The previous behavior was
#also inconsistent in that it allowed an moving to offset 1, 2, ..., but not 0.

Bug: http://bugs.php.net/53006 (Assigned) stream_get_contents offset max is 1165
      
Changed paths:
    U   php/php-src/trunk/ext/standard/streamsfuncs.c

Modified: php/php-src/trunk/ext/standard/streamsfuncs.c
===================================================================
--- php/php-src/trunk/ext/standard/streamsfuncs.c       2010-10-14 00:09:01 UTC 
(rev 304379)
+++ php/php-src/trunk/ext/standard/streamsfuncs.c       2010-10-14 02:03:18 UTC 
(rev 304380)
@@ -425,9 +425,12 @@

        php_stream_from_zval(stream, &zsrc);

-       if ((pos > 0 || (pos == 0 && ZEND_NUM_ARGS() > 2)) && 
php_stream_seek(stream, pos, SEEK_SET) < 0) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to 
position %ld in the stream", pos);
+       if ((pos != 0L) && php_stream_seek(stream, pos, SEEK_CUR) < 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek %ld 
bytes from current position in the stream", pos);
                RETURN_FALSE;
+       } else if (pos < 0L) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of bytes to 
seek must be non-negative, given %ld", pos);
+               RETURN_FALSE;
        }

        len = php_stream_copy_to_mem(stream, &contents, maxlen, 0);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to