forked from Mirrorlandia_minetest/irrlicht
CImageLoaderBMP: check bitmap data against required size
This commit is contained in:
parent
a5c9945bb8
commit
028cb8dbed
@ -290,14 +290,17 @@ IImage* CImageLoaderBMP::loadImage(io::IReadFile* file) const
|
|||||||
|
|
||||||
file->seek(header.BitmapDataOffset);
|
file->seek(header.BitmapDataOffset);
|
||||||
|
|
||||||
f32 t = (header.Width) * (header.BPP / 8.0f);
|
s32 widthInBytes;
|
||||||
s32 widthInBytes = (s32)t;
|
{
|
||||||
t -= widthInBytes;
|
f32 t = (header.Width) * (header.BPP / 8.0f);
|
||||||
if (t!=0.0f)
|
widthInBytes = (s32)t;
|
||||||
++widthInBytes;
|
t -= widthInBytes;
|
||||||
|
if (t!=0.0f)
|
||||||
|
++widthInBytes;
|
||||||
|
}
|
||||||
|
|
||||||
s32 lineData = widthInBytes + ((4-(widthInBytes%4)))%4;
|
const s32 lineSize = widthInBytes + ((4-(widthInBytes%4)))%4;
|
||||||
pitch = lineData - widthInBytes;
|
pitch = lineSize - widthInBytes;
|
||||||
|
|
||||||
u8* bmpData = new u8[header.BitmapDataSize];
|
u8* bmpData = new u8[header.BitmapDataSize];
|
||||||
file->read(bmpData, header.BitmapDataSize);
|
file->read(bmpData, header.BitmapDataSize);
|
||||||
@ -307,15 +310,24 @@ IImage* CImageLoaderBMP::loadImage(io::IReadFile* file) const
|
|||||||
{
|
{
|
||||||
case 1: // 8 bit rle
|
case 1: // 8 bit rle
|
||||||
decompress8BitRLE(bmpData, header.BitmapDataSize, header.Width, header.Height, pitch);
|
decompress8BitRLE(bmpData, header.BitmapDataSize, header.Width, header.Height, pitch);
|
||||||
|
header.BitmapDataSize = (header.Width + pitch) * header.Height;
|
||||||
break;
|
break;
|
||||||
case 2: // 4 bit rle
|
case 2: // 4 bit rle
|
||||||
decompress4BitRLE(bmpData, header.BitmapDataSize, header.Width, header.Height, pitch);
|
decompress4BitRLE(bmpData, header.BitmapDataSize, header.Width, header.Height, pitch);
|
||||||
|
header.BitmapDataSize = ((header.Width+1)/2 + pitch) * header.Height;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create surface
|
if (header.BitmapDataSize < lineSize * header.Height)
|
||||||
|
{
|
||||||
|
os::Printer::log("Bitmap data is cut off.", ELL_ERROR);
|
||||||
|
|
||||||
// no default constructor from packed area! ARM problem!
|
delete [] paletteData;
|
||||||
|
delete [] bmpData;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create surface
|
||||||
core::dimension2d<u32> dim;
|
core::dimension2d<u32> dim;
|
||||||
dim.Width = header.Width;
|
dim.Width = header.Width;
|
||||||
dim.Height = header.Height;
|
dim.Height = header.Height;
|
||||||
|
Loading…
Reference in New Issue
Block a user