Skip to content
Snippets Groups Projects
Commit 5205be0c authored by pavelkproductengine's avatar pavelkproductengine
Browse files

STORM-2148 Crash on trying to save texture file(s) to computer from inventory

parent 5e905cf8
No related branches found
No related tags found
No related merge requests found
...@@ -1304,6 +1304,7 @@ Sovereign Engineer ...@@ -1304,6 +1304,7 @@ Sovereign Engineer
MAINT-6218 MAINT-6218
MAINT-6913 MAINT-6913
STORM-2143 STORM-2143
STORM-2148
SpacedOut Frye SpacedOut Frye
VWR-34 VWR-34
VWR-45 VWR-45
......
...@@ -124,12 +124,12 @@ bool LLImagePNG::encode(const LLImageRaw* raw_image, F32 encode_time) ...@@ -124,12 +124,12 @@ bool LLImagePNG::encode(const LLImageRaw* raw_image, F32 encode_time)
// Temporary buffer to hold the encoded image. Note: the final image // Temporary buffer to hold the encoded image. Note: the final image
// size should be much smaller due to compression. // size should be much smaller due to compression.
U32 bufferSize = getWidth() * getHeight() * getComponents() + 1024; U32 bufferSize = getWidth() * getHeight() * getComponents() + 8192;
U8* tmpWriteBuffer = new U8[ bufferSize ]; U8* tmpWriteBuffer = new U8[ bufferSize ];
// Delegate actual encoding work to wrapper // Delegate actual encoding work to wrapper
LLPngWrapper pngWrapper; LLPngWrapper pngWrapper;
if (! pngWrapper.writePng(raw_image, tmpWriteBuffer)) if (!pngWrapper.writePng(raw_image, tmpWriteBuffer, bufferSize))
{ {
setLastError(pngWrapper.getErrorMessage()); setLastError(pngWrapper.getErrorMessage());
delete[] tmpWriteBuffer; delete[] tmpWriteBuffer;
......
...@@ -112,6 +112,11 @@ void LLPngWrapper::readDataCallback(png_structp png_ptr, png_bytep dest, png_siz ...@@ -112,6 +112,11 @@ void LLPngWrapper::readDataCallback(png_structp png_ptr, png_bytep dest, png_siz
void LLPngWrapper::writeDataCallback(png_structp png_ptr, png_bytep src, png_size_t length) void LLPngWrapper::writeDataCallback(png_structp png_ptr, png_bytep src, png_size_t length)
{ {
PngDataInfo *dataInfo = (PngDataInfo *) png_get_io_ptr(png_ptr); PngDataInfo *dataInfo = (PngDataInfo *) png_get_io_ptr(png_ptr);
if (dataInfo->mOffset + length > dataInfo->mDataSize)
{
png_error(png_ptr, "Data write error. Requested data size exceeds available data size.");
return;
}
U8 *dest = &dataInfo->mData[dataInfo->mOffset]; U8 *dest = &dataInfo->mData[dataInfo->mOffset];
memcpy(dest, src, length); memcpy(dest, src, length);
dataInfo->mOffset += static_cast<U32>(length); dataInfo->mOffset += static_cast<U32>(length);
...@@ -272,7 +277,7 @@ void LLPngWrapper::updateMetaData() ...@@ -272,7 +277,7 @@ void LLPngWrapper::updateMetaData()
// Method to write raw image into PNG at dest. The raw scanline begins // Method to write raw image into PNG at dest. The raw scanline begins
// at the bottom of the image per SecondLife conventions. // at the bottom of the image per SecondLife conventions.
BOOL LLPngWrapper::writePng(const LLImageRaw* rawImage, U8* dest) BOOL LLPngWrapper::writePng(const LLImageRaw* rawImage, U8* dest, size_t destSize)
{ {
try try
{ {
...@@ -313,6 +318,7 @@ BOOL LLPngWrapper::writePng(const LLImageRaw* rawImage, U8* dest) ...@@ -313,6 +318,7 @@ BOOL LLPngWrapper::writePng(const LLImageRaw* rawImage, U8* dest)
PngDataInfo dataPtr; PngDataInfo dataPtr;
dataPtr.mData = dest; dataPtr.mData = dest;
dataPtr.mOffset = 0; dataPtr.mOffset = 0;
dataPtr.mDataSize = destSize;
png_set_write_fn(mWritePngPtr, &dataPtr, &writeDataCallback, &writeFlush); png_set_write_fn(mWritePngPtr, &dataPtr, &writeDataCallback, &writeFlush);
// Setup image params // Setup image params
......
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
BOOL isValidPng(U8* src); BOOL isValidPng(U8* src);
BOOL readPng(U8* src, S32 dataSize, LLImageRaw* rawImage, ImageInfo *infop = NULL); BOOL readPng(U8* src, S32 dataSize, LLImageRaw* rawImage, ImageInfo *infop = NULL);
BOOL writePng(const LLImageRaw* rawImage, U8* dst); BOOL writePng(const LLImageRaw* rawImage, U8* dst, size_t destSize);
U32 getFinalSize(); U32 getFinalSize();
const std::string& getErrorMessage(); const std::string& getErrorMessage();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment