From a65b586b184d9837e0586b4df0d2e758ccce63f6 Mon Sep 17 00:00:00 2001
From: AndreyL ProductEngine <alihatskiy@productengine.com>
Date: Thu, 8 Dec 2016 17:21:05 +0200
Subject: [PATCH] MAINT-6729 Additional fix for crash in
 LLImageGL::analyzeAlpha()

---
 indra/llimage/llimage.cpp    | 2 +-
 indra/llimage/llimage.h      | 2 +-
 indra/llrender/llimagegl.cpp | 6 ++++++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp
index 43b6b3bcd6b..a07ea146212 100644
--- a/indra/llimage/llimage.cpp
+++ b/indra/llimage/llimage.cpp
@@ -800,7 +800,7 @@ U8* LLImageBase::getData()
 	return mData; 
 }
 
-bool LLImageBase::isBufferInvalid()
+bool LLImageBase::isBufferInvalid() const
 {
 	return mBadBufferAllocation || mData == NULL ;
 }
diff --git a/indra/llimage/llimage.h b/indra/llimage/llimage.h
index 9cc7431a9cf..d0bd4a2aefe 100644
--- a/indra/llimage/llimage.h
+++ b/indra/llimage/llimage.h
@@ -141,7 +141,7 @@ class LLImageBase
 
 	const U8 *getData() const	;
 	U8 *getData()				;
-	bool isBufferInvalid() ;
+	bool isBufferInvalid() const;
 
 	void setSize(S32 width, S32 height, S32 ncomponents);
 	U8* allocateDataSize(S32 width, S32 height, S32 ncomponents, S32 size = -1); // setSize() + allocateData()
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index 81a5537f78d..20cba68f847 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -1267,6 +1267,12 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S
 	llassert(gGLManager.mInited);
 	stop_glerror();
 
+	if (!imageraw || imageraw->isBufferInvalid())
+	{
+		LL_WARNS() << "Trying to create a texture from invalid image data" << LL_ENDL;
+		return FALSE;
+	}
+
 	if (discard_level < 0)
 	{
 		llassert(mCurrentDiscardLevel >= 0);
-- 
GitLab