]> granicus.if.org Git - php/commitdiff
merge fix for #37158 into HEAD
authorAntony Dovgal <tony2001@php.net>
Sat, 22 Apr 2006 23:49:39 +0000 (23:49 +0000)
committerAntony Dovgal <tony2001@php.net>
Sat, 22 Apr 2006 23:49:39 +0000 (23:49 +0000)
add test

ext/standard/tests/file/bug37158.phpt [new file with mode: 0644]
main/streams/php_streams_int.h
main/streams/streams.c
main/streams/userspace.c

diff --git a/ext/standard/tests/file/bug37158.phpt b/ext/standard/tests/file/bug37158.phpt
new file mode 100644 (file)
index 0000000..d071569
--- /dev/null
@@ -0,0 +1,43 @@
+--TEST--
+Bug #37158 (if userspace stream is present, fread() reads in 8192 max, otherwise it works)
+--FILE--
+<?php
+
+class VariableStream {
+   
+   function stream_open($path, $mode, $options, &$opened_path) 
+   {
+       return true;
+   }
+}
+
+stream_wrapper_register("var", "VariableStream");
+
+error_reporting(E_ALL | E_STRICT);
+$file = dirname(__FILE__) . '/footest.txt';
+$x = str_repeat(1, 8192);
+$fp = fopen($file, 'w');
+for ($i = 0; $i < 5; $i++) {
+       fwrite($fp, $x);
+}
+fclose($fp);
+
+$fp = fopen($file, 'r');
+$outsidecontents = fread($fp, 20000);
+fclose($fp);
+var_dump('size of contents 1 = ' . strlen($outsidecontents));
+$outsidecontents = file_get_contents($file);
+var_dump('size of contents 2 = ' . strlen($outsidecontents));
+
+unlink($file);
+
+echo "Done\n";
+?>
+--EXPECT--     
+string(26) "size of contents 1 = 20000"
+string(26) "size of contents 2 = 40960"
+Done
+--UEXPECT--    
+unicode(26) "size of contents 1 = 20000"
+unicode(26) "size of contents 2 = 40960"
+Done
index 96da8a0f1d23479d172cbaf42fe9872fd8b7ba7f..8b83a77763ec076f760a019eff275ead5d7355bb 100644 (file)
@@ -46,7 +46,6 @@
 
 #define STREAM_DEBUG 0
 #define STREAM_WRAPPER_PLAIN_FILES     ((php_stream_wrapper*)-1)
-extern php_stream_wrapper php_plain_files_wrapper;
 
 #ifndef MAP_FAILED
 #define MAP_FAILED ((void *) -1)
index 3a8d25b6e34b0f0b0c86fceb839a9b0ff84d4f08..d5210659cec6526aee92fd5e4e1d8aac1264fdb2 100755 (executable)
@@ -1919,7 +1919,7 @@ PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *w
                return FAILURE;
        }
 
-       return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len, wrapper, sizeof(*wrapper), NULL);
+       return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len, &wrapper, sizeof(wrapper), NULL);
 }
 
 PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC)
@@ -1927,6 +1927,15 @@ PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC)
        return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol));
 }
 
+static void clone_wrapper_hash(TSRMLS_D)
+{
+       php_stream_wrapper *tmp;
+
+       ALLOC_HASHTABLE(FG(stream_wrappers));
+       zend_hash_init(FG(stream_wrappers), 0, NULL, NULL, 1);
+       zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL, &tmp, sizeof(tmp));
+}
+
 /* API for registering VOLATILE wrappers */
 PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC)
 {
@@ -1937,24 +1946,16 @@ PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_w
        }
 
        if (!FG(stream_wrappers)) {
-               php_stream_wrapper tmpwrapper;
-
-               ALLOC_HASHTABLE(FG(stream_wrappers));
-               zend_hash_init(FG(stream_wrappers), 0, NULL, NULL, 1);
-               zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL, &tmpwrapper, sizeof(php_stream_wrapper));
+               clone_wrapper_hash(TSRMLS_C);
        }
 
-       return zend_hash_add(FG(stream_wrappers), protocol, protocol_len, wrapper, sizeof(*wrapper), NULL);
+       return zend_hash_add(FG(stream_wrappers), protocol, protocol_len, &wrapper, sizeof(wrapper), NULL);
 }
 
 PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC)
 {
        if (!FG(stream_wrappers)) {
-               php_stream_wrapper tmpwrapper;
-
-               ALLOC_HASHTABLE(FG(stream_wrappers));
-               zend_hash_init(FG(stream_wrappers), 0, NULL, NULL, 1);
-               zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL, &tmpwrapper, sizeof(php_stream_wrapper));
+               clone_wrapper_hash(TSRMLS_C);
        }
 
        return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol));
@@ -1965,7 +1966,7 @@ PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC)
 PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char **path_for_open, int options TSRMLS_DC)
 {
        HashTable *wrapper_hash = (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash);
-       php_stream_wrapper *wrapper = NULL;
+       php_stream_wrapper **wrapperpp = NULL;
        const char *p, *protocol = NULL;
        int n = 0;
 
@@ -1991,7 +1992,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
        }
 
        if (protocol)   {
-               if (FAILURE == zend_hash_find(wrapper_hash, (char*)protocol, n, (void**)&wrapper))      {
+               if (FAILURE == zend_hash_find(wrapper_hash, (char*)protocol, n, (void**)&wrapperpp))    {
                        char wrapper_name[32];
 
                        if (n >= sizeof(wrapper_name))
@@ -2001,7 +2002,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
                        php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unable to find the wrapper \"%s\" - did you forget to enable it when you configured PHP?",
                                        wrapper_name);
 
-                       wrapper = NULL;
+                       wrapperpp = NULL;
                        protocol = NULL;
                }
        }
@@ -2046,14 +2047,14 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
                if (FG(stream_wrappers)) {
                        /* The file:// wrapper may have been disabled/overridden */
 
-                       if (wrapper) {
+                       if (wrapperpp) {
                                /* It was found so go ahead and provide it */
-                               return wrapper;
+                               return *wrapperpp;
                        }
                        
                        /* Check again, the original check might have not known the protocol name */
-                       if (zend_hash_find(wrapper_hash, "file", sizeof("file")-1, (void**)&wrapper) == SUCCESS) {
-                               return wrapper;
+                       if (zend_hash_find(wrapper_hash, "file", sizeof("file")-1, (void**)&wrapperpp) == SUCCESS) {
+                               return *wrapperpp;
                        }
 
                        if (options & REPORT_ERRORS) {
@@ -2066,14 +2067,14 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
                return &php_plain_files_wrapper;
        }
 
-       if ((wrapper && wrapper->is_url) && (!PG(allow_url_fopen) || ((options & STREAM_OPEN_FOR_INCLUDE) && !PG(allow_url_include))) ) {
+       if ((wrapperpp && (*wrapperpp)->is_url) && (!PG(allow_url_fopen) || ((options & STREAM_OPEN_FOR_INCLUDE) && !PG(allow_url_include))) ) {
                if (options & REPORT_ERRORS) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "URL file-access is disabled in the server configuration");
                }
                return NULL;
        }
 
-       return wrapper;
+       return *wrapperpp;
 }
 /* }}} */
 
index eeeb7140c7ed27d096dc77579cc3a26fdee7f2c5..5091dfdbe98515f003ce903415a12fc742e8a875 100644 (file)
@@ -464,7 +464,7 @@ PHP_FUNCTION(stream_wrapper_restore)
 {
        char *protocol;
        int protocol_len;
-       php_stream_wrapper *wrapper = NULL;
+       php_stream_wrapper **wrapperpp = NULL, *wrapper;
        HashTable *global_wrapper_hash;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &protocol, &protocol_len) == FAILURE) {
@@ -477,11 +477,14 @@ PHP_FUNCTION(stream_wrapper_restore)
                RETURN_TRUE;
        }
 
-       if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len, (void**)&wrapper) == FAILURE) || !wrapper) {
+       if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len, (void**)&wrapperpp) == FAILURE) || !wrapperpp) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// never existed, nothing to restore", protocol);
                RETURN_FALSE;
        }
 
+       /* next line might delete the pointer that wrapperpp points at, so deref it now */
+       wrapper = *wrapperpp;
+
        /* A failure here could be okay given that the protocol might have been merely unregistered */
        php_unregister_url_stream_wrapper_volatile(protocol TSRMLS_CC);