From 5f9bd3e7c861b2db8f9620850ea7a4eea1c1778a Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Mon, 19 Oct 2009 19:22:55 +0000 Subject: [PATCH] * Reduce memory consumption when processing very long lines by at least doubleing the size of the new buffer each time. PR: 48024 Submitted by: Basant Kumar Kukreja Reviewed by: rpluem git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@826772 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ modules/filters/sed1.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGES b/CHANGES index cee9e51102..6973be2319 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,9 @@ Changes with Apache 2.3.3 mod_proxy_ftp: NULL pointer dereference on error paths. [Stefan Fritsch , Joe Orton] + *) mod_sed: Reduce memory consumption when processing very long lines. + PR 48024 [Basant Kumar Kukreja ] + *) ab: Fix segfault in case the argument for -n is a very large number. PR 47178. [Philipp Hagemeister ] diff --git a/modules/filters/sed1.c b/modules/filters/sed1.c index 24f16f0501..af26065365 100644 --- a/modules/filters/sed1.c +++ b/modules/filters/sed1.c @@ -99,6 +99,12 @@ static void grow_buffer(apr_pool_t *pool, char **buffer, int spendsize = 0; if (*cursize >= newsize) return; + /* Avoid number of times realloc is called. It could cause huge memory + * requirement if line size is huge e.g 2 MB */ + if (newsize < *cursize * 2) { + newsize = *cursize * 2; + } + /* Align it to 4 KB boundary */ newsize = (newsize + ((1 << 12) - 1)) & ~((1 << 12) -1); newbuffer = apr_pcalloc(pool, newsize); -- 2.40.0