From eadca6285716400e75eeb26a509018c67819b34e Mon Sep 17 00:00:00 2001 From: Ansariel Date: Sat, 23 Mar 2013 21:43:50 +0100 Subject: [PATCH] Pull fix for heap corruption warning due to freeing new[]'ed memory with free() from Kitty Barnett / Catznip viewer --- indra/llimage/llimagej2c.cpp | 18 +++++++++++++++--- indra/llimage/llimagej2c.h | 5 ++++- indra/newview/llviewertexlayer.cpp | 7 ++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/indra/llimage/llimagej2c.cpp b/indra/llimage/llimagej2c.cpp index 2883d65dfd..ea51b726c4 100644 --- a/indra/llimage/llimagej2c.cpp +++ b/indra/llimage/llimagej2c.cpp @@ -396,7 +396,10 @@ BOOL LLImageJ2C::loadAndValidate(const std::string &filename) } else { - res = validate(data, file_size); +// [SL:KB] - Patch: Viewer-ImageBaseHeapCorruption | Checked: 2012-08-12 (Catznip-3.3) + res = validate(data, file_size, false); +// [/SL:KB] +// res = validate(data, file_size); } } @@ -409,12 +412,21 @@ BOOL LLImageJ2C::loadAndValidate(const std::string &filename) } -BOOL LLImageJ2C::validate(U8 *data, U32 file_size) +//BOOL LLImageJ2C::validate(U8 *data, U32 file_size) +// [SL:KB] - Patch: Viewer-ImageBaseHeapCorruption | Checked: 2012-08-12 (Catznip-3.3) +BOOL LLImageJ2C::validate(U8 *data, U32 file_size, bool copy_data) +// [/SL:KB] { resetLastError(); - setData(data, file_size); +// [SL:KB] - Patch: Viewer-ImageBaseHeapCorruption | Checked: 2012-08-12 (Catznip-3.3) + if (!copy_data) + setData(data, file_size); + else + copyData(data, file_size); +// [/SL:KB] +// setData(data, file_size); BOOL res = updateData(); if ( res ) diff --git a/indra/llimage/llimagej2c.h b/indra/llimage/llimagej2c.h index ce8195940d..c1f549e549 100644 --- a/indra/llimage/llimagej2c.h +++ b/indra/llimage/llimagej2c.h @@ -65,7 +65,10 @@ public: // Encode with comment text BOOL encode(const LLImageRaw *raw_imagep, const char* comment_text, F32 encode_time=0.0); - BOOL validate(U8 *data, U32 file_size); +// BOOL validate(U8 *data, U32 file_size); +// [SL:KB] - Patch: Viewer-ImageBaseHeapCorruption | Checked: 2012-08-12 (Catznip-3.3) + BOOL validate(U8 *data, U32 file_size, bool copy_data); +// [/SL:KB] BOOL loadAndValidate(const std::string &filename); // Encode accessors diff --git a/indra/newview/llviewertexlayer.cpp b/indra/newview/llviewertexlayer.cpp index f3c9921819..bc7178149b 100755 --- a/indra/newview/llviewertexlayer.cpp +++ b/indra/newview/llviewertexlayer.cpp @@ -422,7 +422,12 @@ void LLViewerTexLayerSetBuffer::doUpload() file.read(data, file_size); if (data) { - valid = integrity_test->validate(data, file_size); // integrity_test will delete 'data' +// [SL:KB] - Patch: Viewer-ImageBaseHeapCorruption | Checked: 2012-08-12 (Catznip-3.3) + // Image data needs copying since 'data' was allocated with new[] and LLImageBase wants malloc or pool allocated memory + valid = integrity_test->validate(data, file_size, true); + delete[] data; +// [/SL:KB] +// valid = integrity_test->validate(data, file_size); // integrity_test will delete 'data' } else {