commit 185e8e1: [Project] Improve inflation

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Jan 4 18:14:06 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-01-04 18:12:03 +0000
URL: https://github.com/rspamd/rspamd/commit/185e8e1239cfd0db4dbe048e1bab2a3e8561edbb

[Project] Improve inflation

---
 src/lua/lua_util.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index d915085fc..ae1a020a1 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -2356,9 +2356,15 @@ lua_util_zlib_inflate (lua_State *L, int windowBits)
 
 	if (lua_type (L, 2) == LUA_TNUMBER) {
 		size_limit = lua_tointeger (L, 2);
-	}
+		if (size_limit <= 0) {
+			return luaL_error (L, "invalid arguments (size_limit)");
+		}
 
-	sz = t->len;
+		sz = MIN (t->len * 2, size_limit);
+	}
+	else {
+		sz = t->len * 2;
+	}
 
 	memset (&strm, 0, sizeof (strm));
 	/* windowBits +16 to decode gzip, zlib 1.2.0.4+ */
@@ -2436,7 +2442,7 @@ lua_util_gzip_decompress (lua_State *L)
 static gint
 lua_util_inflate (lua_State *L)
 {
-	return lua_util_zlib_inflate (L, 0);
+	return lua_util_zlib_inflate (L, MAX_WBITS);
 }
 
 static gint


More information about the Commits mailing list