mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-10 14:41:50 +00:00
loader/svg: Add null to the end of data
Because memcpy() is not guaranteed to copy null at the end of the data array, it increase the size by 1 and add null This prevents invalid access of string functions in parser.
This commit is contained in:
parent
6406a369a5
commit
66c43352ef
2 changed files with 5 additions and 4 deletions
|
@ -3813,10 +3813,11 @@ bool SvgLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& r
|
|||
clear();
|
||||
|
||||
if (copy) {
|
||||
content = (char*)malloc(size);
|
||||
content = (char*)malloc(size + 1);
|
||||
if (!content) return false;
|
||||
memcpy((char*)content, data, size);
|
||||
} else content = data;
|
||||
content[size] = '\0';
|
||||
} else content = (char*)data;
|
||||
|
||||
this->size = size;
|
||||
this->copy = copy;
|
||||
|
@ -3840,7 +3841,7 @@ bool SvgLoader::open(const string& path)
|
|||
|
||||
if (filePath.empty()) return false;
|
||||
|
||||
content = filePath.c_str();
|
||||
content = (char*)filePath.c_str();
|
||||
size = filePath.size();
|
||||
|
||||
return header();
|
||||
|
|
|
@ -31,7 +31,7 @@ class SvgLoader : public ImageLoader, public Task
|
|||
public:
|
||||
string filePath;
|
||||
string svgPath = "";
|
||||
const char* content = nullptr;
|
||||
char* content = nullptr;
|
||||
uint32_t size = 0;
|
||||
|
||||
SvgLoaderData loaderData;
|
||||
|
|
Loading…
Add table
Reference in a new issue