]> granicus.if.org Git - php/commitdiff
Fixed bug #48034 (PHP crashes when script is 8192 (8KB) bytes long)
authorDmitry Stogov <dmitry@php.net>
Tue, 28 Apr 2009 07:13:43 +0000 (07:13 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 28 Apr 2009 07:13:43 +0000 (07:13 +0000)
main/main.c

index 48c10ecb5d2c69a9365f75544b35a703155deeec..865feca6deed48e688d194049b32a2bb215d375e 100644 (file)
 
 #include "SAPI.h"
 #include "rfc1867.h"
+
+#if HAVE_SYS_MMAN_H
+# include <sys/mman.h>
+# ifndef PAGE_SIZE
+#  define PAGE_SIZE 4096
+# endif
+#endif
 /* }}} */
 
 PHPAPI int (*php_register_internal_extensions_func)(TSRMLS_D) = php_register_internal_extensions;
@@ -1237,8 +1244,10 @@ PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *h
                handle->handle.stream.isatty  = 0;
                /* can we mmap immeadiately? */
                memset(&handle->handle.stream.mmap, 0, sizeof(handle->handle.stream.mmap));
-               len = php_zend_stream_fsizer(stream TSRMLS_CC) + ZEND_MMAP_AHEAD;
-               if (php_stream_mmap_possible(stream)
+               len = php_zend_stream_fsizer(stream TSRMLS_CC);
+               if (len != 0
+               && ((len - 1) % PAGE_SIZE) <= PAGE_SIZE - ZEND_MMAP_AHEAD
+               && php_stream_mmap_possible(stream)
                && (p = php_stream_mmap_range(stream, 0, len, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped_len)) != NULL) {
                        handle->handle.stream.closer   = php_zend_stream_mmap_closer;
                        handle->handle.stream.mmap.buf = p;