From 973f07db7982e78c634c29f6139dea547a111141 Mon Sep 17 00:00:00 2001 From: Armin Weatherwax Date: Wed, 3 Feb 2010 17:10:57 +0100 Subject: Fixed a rare crash from textures with too many components. Only seen in lbsa plaza on OSGrid, so far. --- linden/indra/llimagej2coj/llimagej2coj.cpp | 29 +++++++++++++++++------- linden/indra/llrender/llimagegl.cpp | 4 +++- linden/indra/newview/app_settings/logcontrol.xml | 2 +- 3 files changed, 25 insertions(+), 10 deletions(-) (limited to 'linden') diff --git a/linden/indra/llimagej2coj/llimagej2coj.cpp b/linden/indra/llimagej2coj/llimagej2coj.cpp index be6b6c8..b7a1b82 100644 --- a/linden/indra/llimagej2coj/llimagej2coj.cpp +++ b/linden/indra/llimagej2coj/llimagej2coj.cpp @@ -99,6 +99,7 @@ void info_callback(const char* msg, void*) LLImageJ2COJ::LLImageJ2COJ() : LLImageJ2CImpl() { + mRawImagep=NULL; } @@ -166,9 +167,17 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod // The image decode failed if the return was NULL or the component // count was zero. The latter is just a sanity check before we // dereference the array. - if(!image || !image->numcomps) + if(!image) { - llwarns << "ERROR -> decodeImpl: failed to decode image!" << llendl; + LL_DEBUGS("Openjpeg") << "ERROR -> decodeImpl: failed to decode image - no image" << LL_ENDL; + return TRUE; // done + } + + S32 img_components = image->numcomps; + + if( !img_components ) // < 1 ||img_components > 4 ) + { + LL_DEBUGS("Openjpeg") << "ERROR -> decodeImpl: failed to decode image wrong number of components: " << img_components << LL_ENDL; if (image) { opj_image_destroy(image); @@ -178,20 +187,21 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod } // sometimes we get bad data out of the cache - check to see if the decode succeeded - for (S32 i = 0; i < image->numcomps; i++) + for (S32 i = 0; i < img_components; i++) { if (image->comps[i].factor != base.getRawDiscardLevel()) { // if we didn't get the discard level we're expecting, fail - opj_image_destroy(image); + if (image) //anyway somthing odd with the image, better check than crash + opj_image_destroy(image); base.mDecoding = FALSE; return TRUE; } } - if(image->numcomps <= first_channel) + if(img_components <= first_channel) { - llwarns << "trying to decode more channels than are present in image: numcomps: " << image->numcomps << " first_channel: " << first_channel << llendl; + LL_DEBUGS("Openjpeg") << "trying to decode more channels than are present in image: numcomps: " << img_components << " first_channel: " << first_channel << LL_ENDL; if (image) { opj_image_destroy(image); @@ -202,7 +212,7 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod // Copy image data into our raw image format (instead of the separate channel format - S32 img_components = image->numcomps; + S32 channels = img_components - first_channel; if( channels > max_channel_count ) channels = max_channel_count; @@ -249,7 +259,10 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod } /* free image data structure */ - opj_image_destroy(image); + if (image) + { + opj_image_destroy(image); + } return TRUE; // done } diff --git a/linden/indra/llrender/llimagegl.cpp b/linden/indra/llrender/llimagegl.cpp index 27b1d55..544eb80 100644 --- a/linden/indra/llrender/llimagegl.cpp +++ b/linden/indra/llrender/llimagegl.cpp @@ -1014,7 +1014,9 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S mFormatType = GL_UNSIGNED_BYTE; break; default: - llerrs << "Bad number of components for texture: " << (U32)getComponents() << llendl; + LL_DEBUGS("Openjpeg") << "Bad number of components for texture: " << (U32)getComponents() << LL_ENDL; + to_create = false; + break; } } diff --git a/linden/indra/newview/app_settings/logcontrol.xml b/linden/indra/newview/app_settings/logcontrol.xml index 60f78b7..401b145 100644 --- a/linden/indra/newview/app_settings/logcontrol.xml +++ b/linden/indra/newview/app_settings/logcontrol.xml @@ -51,7 +51,7 @@ MediaState ShaderLoading XMLNode - + Openjpeg