From f22c1bcf2014346211ecc32c21d48cc88aca8e07 Mon Sep 17 00:00:00 2001
From: andreykproductengine <andreykproductengine@lindenlab.com>
Date: Mon, 19 Feb 2018 21:30:48 +0200
Subject: [PATCH] MAINT-8022 Handling memory errors in unzip_llsdNavMesh

---
 indra/llcommon/llsdserialize.cpp | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp
index 580e87954bb..26a49676599 100644
--- a/indra/llcommon/llsdserialize.cpp
+++ b/indra/llcommon/llsdserialize.cpp
@@ -2262,13 +2262,24 @@ LLUZipHelper::EZipRresult LLUZipHelper::unzip_llsd(LLSD& data, std::istream& is,
 //and trailers are different for the formats.
 U8* unzip_llsdNavMesh( bool& valid, unsigned int& outsize, std::istream& is, S32 size )
 {
+	if (size == 0)
+	{
+		LL_WARNS() << "No data to unzip." << LL_ENDL;
+		return NULL;
+	}
+
 	U8* result = NULL;
 	U32 cur_size = 0;
 	z_stream strm;
 		
 	const U32 CHUNK = 0x4000;
 
-	U8 *in = new U8[size];
+	U8 *in = new(std::nothrow) U8[size];
+	if (in == NULL)
+	{
+		LL_WARNS() << "Memory allocation failure." << LL_ENDL;
+		return NULL;
+	}
 	is.read((char*) in, size); 
 
 	U8 out[CHUNK];
-- 
GitLab