extend SVG fix to LoadImage(FromMemory)
fix the same buffer overflow error from loading an SVG on LoadImage Fix is on LoadImage LoadImageFromMemory now checks for terminating NULL on SVG files
This commit is contained in:
parent
945a4c69b3
commit
67714a032c
|
|
@ -291,11 +291,21 @@ Image LoadImage(const char *fileName)
|
|||
// Loading file to memory
|
||||
int dataSize = 0;
|
||||
unsigned char *fileData = LoadFileData(fileName, &dataSize);
|
||||
const char *fileType = GetFileExtension(fileName);
|
||||
|
||||
#if defined(SUPPORT_FILEFORMAT_SVG)
|
||||
if ((strcmp(fileType, ".svg") == 0) || (strcmp(fileType, ".SVG") == 0))
|
||||
{
|
||||
fileData = RL_REALLOC(fileData, dataSize+1);
|
||||
fileData[dataSize] = '\0';
|
||||
dataSize++;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Loading image from memory data
|
||||
if (fileData != NULL)
|
||||
{
|
||||
image = LoadImageFromMemory(GetFileExtension(fileName), fileData, dataSize);
|
||||
image = LoadImageFromMemory(fileType, fileData, dataSize);
|
||||
|
||||
UnloadFileData(fileData);
|
||||
}
|
||||
|
|
@ -618,6 +628,10 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
|
|||
(fileData[1] == 's') &&
|
||||
(fileData[2] == 'v') &&
|
||||
(fileData[3] == 'g'))
|
||||
{
|
||||
// make sure that fileData is a NULL terminated String
|
||||
// as required by nsvgParse()
|
||||
if (fileData[dataSize-1] == '\0')
|
||||
{
|
||||
struct NSVGimage *svgImage = nsvgParse(fileData, "px", 96.0f);
|
||||
unsigned char *img = RL_MALLOC(svgImage->width*svgImage->height*4);
|
||||
|
|
@ -636,6 +650,8 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
|
|||
nsvgDelete(svgImage);
|
||||
nsvgDeleteRasterizer(rast);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "IMAGE: SVG image data must be NULL terminated");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(SUPPORT_FILEFORMAT_DDS)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user