diff --git a/source/Irrlicht/CImageLoaderTGA.cpp b/source/Irrlicht/CImageLoaderTGA.cpp index ce36e23a..bb0814a0 100644 --- a/source/Irrlicht/CImageLoaderTGA.cpp +++ b/source/Irrlicht/CImageLoaderTGA.cpp @@ -63,8 +63,13 @@ u8 *CImageLoaderTGA::loadCompressedImage(io::IReadFile *file, const STGAHeader& for(s32 counter = 1; counter < chunkheader; counter++) { - for(s32 elementCounter=0; elementCounter < bytesPerPixel; elementCounter++) - data[currentByte + elementCounter] = data[dataOffset + elementCounter]; + if ( currentByte + bytesPerPixel <= imageSize ) + { + for(s32 elementCounter=0; elementCounter < bytesPerPixel; elementCounter++) + { + data[currentByte + elementCounter] = data[dataOffset + elementCounter]; + } + } currentByte += bytesPerPixel; }