From 0fb4bf9771051eb8cd37d83d4d8c26e6957986eb Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 21 Apr 2004 12:02:47 +0000 Subject: [PATCH] Fixed bug #19749 (shouldn't mmap() files larger than memory_limit) --- NEWS | 1 + main/streams/mmap.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 9335b99a35..7ec1278b86 100644 --- a/NEWS +++ b/NEWS @@ -41,6 +41,7 @@ PHP NEWS - Fixed bug #27397 (debug_backtrace() not showing function arguments). (Zeev) - Fixed bug #27283 (The last catch statement was sometimes skipped). (Andi) - Fixed bug #26441 (When __set() returned a value it corrupted it). (Andi) +- Fixed bug #19749 (shouldn't mmap() files larger than memory_limit). (Wez) 18 March 2004, PHP 5 Release Candidate 1 - Fixed numerous bugs with the just-in-time auto-global initialization, that diff --git a/main/streams/mmap.c b/main/streams/mmap.c index 443faf384d..82bfa623f1 100644 --- a/main/streams/mmap.c +++ b/main/streams/mmap.c @@ -31,7 +31,11 @@ PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t le range.mode = mode; range.mapped = NULL; - /* TODO: Enforce system policy and limits for mmap sizes ? */ + /* For now, we impose an arbitrary 1MB limit to avoid + * runaway swapping when large files are passed thru. */ + if (length > 1 * 1024 * 1024) { + return NULL; + } if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_MAP_RANGE, &range)) { if (mapped_len) { -- 2.40.0