mirror of
https://github.com/minetest/irrlicht.git
synced 2025-06-28 14:26:06 +02:00
Add IImage::checkDataSizeLimit and make IImage getDataSizeFromFormat return size_t
It's to allow image loader to check for sane limits for image sizes.
Idea came from this patch from sfan5 for Minetest: dbd39120e7
Thought solution is a bit different.
Image loader checks not yet added (will come soon).
Also note that limit is to s32. While u32 might work mostly it will run into some troubles with color converter for now (which maybe could be changes). Also 2GB ought to be enough for anybody, right?
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6386 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
@ -335,7 +335,7 @@ void CD3D9Texture::regenerateMipMapLevels(void* data, u32 layer)
|
||||
u32 width = Size.Width;
|
||||
u32 height = Size.Height;
|
||||
u8* tmpData = static_cast<u8*>(data);
|
||||
u32 dataSize = 0;
|
||||
size_t dataSize = 0;
|
||||
u32 level = 0;
|
||||
|
||||
do
|
||||
@ -714,7 +714,7 @@ void CD3D9Texture::uploadTexture(void* data, u32 mipmapLevel, u32 layer)
|
||||
u32 width = Size.Width >> mipmapLevel;
|
||||
u32 height = Size.Height >> mipmapLevel;
|
||||
|
||||
u32 dataSize = IImage::getDataSizeFromFormat(ColorFormat, width, height);
|
||||
size_t dataSize = IImage::getDataSizeFromFormat(ColorFormat, width, height);
|
||||
|
||||
HRESULT hr = 0;
|
||||
|
||||
|
@ -24,8 +24,7 @@ CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size, void* d
|
||||
}
|
||||
else
|
||||
{
|
||||
const u32 dataSize = getDataSizeFromFormat(Format, Size.Width, Size.Height);
|
||||
|
||||
const size_t dataSize = getDataSizeFromFormat(Format, Size.Width, Size.Height);
|
||||
Data = new u8[align_next(dataSize,16)];
|
||||
memcpy(Data, data, dataSize);
|
||||
DeleteMemory = true;
|
||||
@ -36,7 +35,8 @@ CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size, void* d
|
||||
//! Constructor of empty image
|
||||
CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size) : IImage(format, size, true)
|
||||
{
|
||||
Data = new u8[align_next(getDataSizeFromFormat(Format, Size.Width, Size.Height),16)];
|
||||
const size_t dataSize = getDataSizeFromFormat(Format, Size.Width, Size.Height);
|
||||
Data = new u8[align_next(dataSize,16)];
|
||||
DeleteMemory = true;
|
||||
}
|
||||
|
||||
@ -332,8 +332,8 @@ void CImage::fill(const SColor &color)
|
||||
{
|
||||
u8 rgb[3];
|
||||
CColorConverter::convert_A8R8G8B8toR8G8B8(&color, 1, rgb);
|
||||
const u32 size = getImageDataSizeInBytes();
|
||||
for (u32 i=0; i<size; i+=3)
|
||||
const size_t size = getImageDataSizeInBytes();
|
||||
for (size_t i=0; i<size; i+=3)
|
||||
{
|
||||
memcpy(Data+i, rgb, 3);
|
||||
}
|
||||
|
@ -693,8 +693,8 @@ IImage* CImageLoaderDDS::loadImage(io::IReadFile* file) const
|
||||
s32 width, height;
|
||||
eDDSPixelFormat pixelFormat;
|
||||
ECOLOR_FORMAT format = ECF_UNKNOWN;
|
||||
u32 dataSize = 0;
|
||||
u32 mipMapsDataSize = 0;
|
||||
size_t dataSize = 0;
|
||||
size_t mipMapsDataSize = 0;
|
||||
bool is3D = false;
|
||||
bool useAlpha = false;
|
||||
u32 mipMapCount = 0;
|
||||
|
@ -69,7 +69,7 @@ core::array<IImage*> CImageLoaderPVR::loadImages(io::IReadFile* file, E_TEXTURE_
|
||||
core::array<u8*> mipMapsDataArray;
|
||||
|
||||
ECOLOR_FORMAT format = ECF_UNKNOWN;
|
||||
u32 dataSize = 0;
|
||||
size_t dataSize = 0;
|
||||
|
||||
file->seek(0);
|
||||
file->read(&header, sizeof(SPVRHeader));
|
||||
@ -216,7 +216,7 @@ core::array<IImage*> CImageLoaderPVR::loadImages(io::IReadFile* file, E_TEXTURE_
|
||||
// read texture
|
||||
|
||||
dataSize = 0;
|
||||
long offset = 0;
|
||||
size_t offset = 0;
|
||||
|
||||
for (u32 i = 0; i < header.MipMapCount; ++i)
|
||||
{
|
||||
|
@ -401,7 +401,7 @@ public:
|
||||
u32 width = Size.Width;
|
||||
u32 height = Size.Height;
|
||||
u8* tmpData = static_cast<u8*>(data);
|
||||
u32 dataSize = 0;
|
||||
size_t dataSize = 0;
|
||||
u32 level = 0;
|
||||
|
||||
do
|
||||
@ -600,7 +600,7 @@ protected:
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 dataSize = IImage::getDataSizeFromFormat(ColorFormat, width, height);
|
||||
GLsizei dataSize = (GLsizei)IImage::getDataSizeFromFormat(ColorFormat, width, height);
|
||||
|
||||
switch (TextureType)
|
||||
{
|
||||
|
Reference in New Issue
Block a user