From b785b9d1ae08f5f05c6c4ebdb127c5debbb225c7 Mon Sep 17 00:00:00 2001 From: Beq Date: Thu, 22 Oct 2020 22:52:02 +0100 Subject: [PATCH] Crash avoidance for compositeUnscaled4onto3 --- indra/llimage/llimage.cpp | 31 +++++++++++++++++++++++++++---- indra/newview/llvlcomposition.cpp | 8 ++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp index 9b33aac1c4..246f3058b1 100644 --- a/indra/llimage/llimage.cpp +++ b/indra/llimage/llimage.cpp @@ -1079,9 +1079,10 @@ void LLImageRaw::composite( LLImageRaw* src ) return; } - llassert(3 == src->getComponents()); - llassert(3 == dst->getComponents()); - +// These assertions are nonsense. + // llassert(3 == src->getComponents()); + // llassert(3 == dst->getComponents()); +// if( 3 == dst->getComponents() ) { if( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) ) @@ -1143,12 +1144,34 @@ void LLImageRaw::compositeUnscaled4onto3( LLImageRaw* src ) { LLImageRaw* dst = this; // Just for clarity. - llassert( (3 == src->getComponents()) || (4 == src->getComponents()) ); + // Correct bad assertion + // llassert( (3 == src->getComponents()) || (4 == src->getComponents()) ); + llassert( (4 == src->getComponents()) || (3 == dst->getComponents()) ); + // llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) ); U8* src_data = src->getData(); U8* dst_data = dst->getData(); S32 pixels = getWidth() * getHeight(); + // suspicious crash avoid potential causes. + if(!src_data) + { + LL_WARNS() << "source is null!" << LL_ENDL; + return; + } + if(!dst_data) + { + LL_WARNS() << "destination is null!" << LL_ENDL; + return; + } + auto src_comps = src->getComponents(); + if( src_comps != 4) + { + // This should never be reached, buit apparently it is. + LL_WARNS() << "src has incorrect number of layers (" << src_comps << ")" << LL_ENDL; + return; + } + // while( pixels-- ) { U8 alpha = src_data[3]; diff --git a/indra/newview/llvlcomposition.cpp b/indra/newview/llvlcomposition.cpp index 25326f7e05..8ba0f89fdc 100644 --- a/indra/newview/llvlcomposition.cpp +++ b/indra/newview/llvlcomposition.cpp @@ -307,6 +307,14 @@ BOOL LLVLComposition::generateTexture(const F32 x, const F32 y, mDetailTextures[i]->getComponents() != 3) { LLPointer newraw = new LLImageRaw(BASE_SIZE, BASE_SIZE, 3); + // guard against bad alloc here that leads to crash in composite + if(!newraw) + { + // Not much that is useful to do here, this ship is sinking it seems. + LL_WARNS("Terrain") << "allocation of new raw image failed" << LL_ENDL; + return(FALSE); + } + // newraw->composite(mRawImages[i]); mRawImages[i] = newraw; // deletes old }