summaryrefslogtreecommitdiff
path: root/indra/llimage/llimagedimensionsinfo.cpp
diff options
context:
space:
mode:
authorOz Linden <oz@lindenlab.com>2010-11-04 11:56:36 -0400
committerOz Linden <oz@lindenlab.com>2010-11-04 11:56:36 -0400
commitc97def552af4564d81b68d36a5d7efc2dce56c54 (patch)
tree73246cf5a4d5963225f611dc35b1f91c216536a5 /indra/llimage/llimagedimensionsinfo.cpp
parent7f0de785585876f34366700d43c89514e37b006f (diff)
parente32ce48d983c3a561dd05dc84eb7b2b7a3b788fb (diff)
merge fix for STORM-261
Diffstat (limited to 'indra/llimage/llimagedimensionsinfo.cpp')
-rw-r--r--indra/llimage/llimagedimensionsinfo.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/indra/llimage/llimagedimensionsinfo.cpp b/indra/llimage/llimagedimensionsinfo.cpp
index 5ea4a236b5..835664c60f 100644
--- a/indra/llimage/llimagedimensionsinfo.cpp
+++ b/indra/llimage/llimagedimensionsinfo.cpp
@@ -30,6 +30,9 @@
#include "llimagedimensionsinfo.h"
+// Value is true if one of Libjpeg's functions has encountered an error while working.
+static bool sJpegErrorEncountered = false;
+
bool LLImageDimensionsInfo::load(const std::string& src_filename,U32 codec)
{
clean();
@@ -101,9 +104,17 @@ bool LLImageDimensionsInfo::getImageDimensionsPng()
return true;
}
+// Called instead of exit() if Libjpeg encounters an error.
+void on_jpeg_error(j_common_ptr cinfo)
+{
+ (void) cinfo;
+ sJpegErrorEncountered = true;
+ llwarns << "Libjpeg has encountered an error!" << llendl;
+}
bool LLImageDimensionsInfo::getImageDimensionsJpeg()
{
+ sJpegErrorEncountered = false;
clean();
FILE *fp = fopen (mSrcFilename.c_str(), "rb");
if (fp == NULL)
@@ -115,6 +126,9 @@ bool LLImageDimensionsInfo::getImageDimensionsJpeg()
jpeg_error_mgr jerr;
jpeg_decompress_struct cinfo;
cinfo.err = jpeg_std_error(&jerr);
+ // Call our function instead of exit() if Libjpeg encounters an error.
+ // This is done to avoid crash in this case (STORM-472).
+ cinfo.err->error_exit = on_jpeg_error;
jpeg_create_decompress (&cinfo);
jpeg_stdio_src (&cinfo, fp);
@@ -128,6 +142,6 @@ bool LLImageDimensionsInfo::getImageDimensionsJpeg()
jpeg_destroy_decompress(&cinfo);
fclose(fp);
- return true;
+ return !sJpegErrorEncountered;
}