From 6d7c19623d44bbd9dcfcd047e3b3ab2120916481 Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Mon, 27 Nov 2017 19:04:41 +0200 Subject: MAINT-8022 Crashes in unzip_llsd --- indra/llcommon/llsdserialize.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/llcommon/llsdserialize.cpp') diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index 3a219eb998..7f286f5e68 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -2188,7 +2188,6 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) U8* new_result = (U8*)realloc(result, cur_size + have); if (new_result == NULL) { - LL_WARNS() << "Failed to unzip LLSD block: can't reallocate memory, current size: " << cur_size << " bytes; requested " << cur_size + have << " bytes." << LL_ENDL; inflateEnd(&strm); if (result) { -- cgit v1.2.3 From dcfccc6f435610077592bbddcef2468c64f27f2f Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Tue, 28 Nov 2017 15:55:40 +0200 Subject: MAINT-8022 Crashes in unzip_llsd #2 --- indra/llcommon/llsdserialize.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'indra/llcommon/llsdserialize.cpp') diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index 7f286f5e68..ede212181d 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -2144,7 +2144,11 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) const U32 CHUNK = 65536; - U8 *in = new U8[size]; + U8 *in = new(std::nothrow) U8[size]; + if (!in) + { + return false; + } is.read((char*) in, size); U8 out[CHUNK]; -- cgit v1.2.3 From a35008993eef5b1fee5695804c83050cf922d146 Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Tue, 2 Jan 2018 20:31:23 +0200 Subject: MAINT-8022 String crashes in unzip_llsd --- indra/llcommon/llsdserialize.cpp | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'indra/llcommon/llsdserialize.cpp') diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index ede212181d..71744aef3c 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -2217,24 +2217,42 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) //result now points to the decompressed LLSD block { - std::string res_str((char*) result, cur_size); + std::istringstream istr; + // Since we are using this for meshes, data we are dealing with tend to be large. + // So string can potentially fail to allocate, make sure this won't cause problems + try + { + std::string res_str((char*)result, cur_size); + + std::string deprecated_header(""); - std::string deprecated_header(""); + if (res_str.substr(0, deprecated_header.size()) == deprecated_header) + { + res_str = res_str.substr(deprecated_header.size() + 1, cur_size); + } + cur_size = res_str.size(); - if (res_str.substr(0, deprecated_header.size()) == deprecated_header) + istr.str(res_str); + } + catch (std::length_error) { - res_str = res_str.substr(deprecated_header.size()+1, cur_size); + LL_DEBUGS("UNZIP") << "String we are creating is too big" << LL_ENDL; + free(result); + return false; + } + catch (std::bad_alloc) + { + LL_DEBUGS("UNZIP") << "Failed to allocate for string" << LL_ENDL; + free(result); + return false; } - cur_size = res_str.size(); - std::istringstream istr(res_str); - if (!LLSDSerialize::fromBinary(data, istr, cur_size)) { - LL_WARNS() << "Failed to unzip LLSD block" << LL_ENDL; + LL_WARNS("UNZIP") << "Failed to unzip LLSD block" << LL_ENDL; free(result); return false; - } + } } free(result); -- cgit v1.2.3 From c56298d4ba818aaa5b69a8c30e5b577f7e4596eb Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Wed, 3 Jan 2018 16:30:57 +0200 Subject: MAINT-8022 Make unzip silent yet include failure reason into output --- indra/llcommon/llsdserialize.cpp | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'indra/llcommon/llsdserialize.cpp') diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index 71744aef3c..be54ed053b 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -2121,22 +2121,13 @@ std::string zip_llsd(LLSD& data) deflateEnd(&strm); free(output); -#if 0 //verify results work with unzip_llsd - std::istringstream test(result); - LLSD test_sd; - if (!unzip_llsd(test_sd, test, result.size())) - { - LL_ERRS() << "Invalid compression result!" << LL_ENDL; - } -#endif - return result; } //decompress a block of LLSD from provided istream // not very efficient -- creats a copy of decompressed LLSD block in memory // and deserializes from that copy using LLSDSerialize -bool unzip_llsd(LLSD& data, std::istream& is, S32 size) +LLUZipHelper::EZipRresult LLUZipHelper::unzip_llsd(LLSD& data, std::istream& is, S32 size) { U8* result = NULL; U32 cur_size = 0; @@ -2147,7 +2138,7 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) U8 *in = new(std::nothrow) U8[size]; if (!in) { - return false; + return ZR_MEM_ERROR; } is.read((char*) in, size); @@ -2171,7 +2162,7 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) inflateEnd(&strm); free(result); delete [] in; - return false; + return ZR_DATA_ERROR; } switch (ret) @@ -2183,7 +2174,7 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) inflateEnd(&strm); free(result); delete [] in; - return false; + return ZR_MEM_ERROR; break; } @@ -2198,7 +2189,7 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) free(result); } delete[] in; - return false; + return ZR_MEM_ERROR; } result = new_result; memcpy(result+cur_size, out, have); @@ -2212,7 +2203,7 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) if (ret != Z_STREAM_END) { free(result); - return false; + return ZR_DATA_ERROR; } //result now points to the decompressed LLSD block @@ -2234,29 +2225,28 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) istr.str(res_str); } +#ifdef LL_WINDOWS catch (std::length_error) { - LL_DEBUGS("UNZIP") << "String we are creating is too big" << LL_ENDL; free(result); - return false; + return ZR_SIZE_ERROR; } +#endif catch (std::bad_alloc) { - LL_DEBUGS("UNZIP") << "Failed to allocate for string" << LL_ENDL; free(result); - return false; + return ZR_MEM_ERROR; } if (!LLSDSerialize::fromBinary(data, istr, cur_size)) { - LL_WARNS("UNZIP") << "Failed to unzip LLSD block" << LL_ENDL; free(result); - return false; + return ZR_PARSE_ERROR; } } free(result); - return true; + return ZR_OK; } //This unzip function will only work with a gzip header and trailer - while the contents //of the actual compressed data is the same for either format (gzip vs zlib ), the headers -- cgit v1.2.3