svg_loader: negative attrs length fix

After finding no attributes but white spaces, attrs length could be negative
that resulted in segmentation fault in simpleXmlParseAttributes function.

@Issue: #487
This commit is contained in:
Michal Maciola 2021-06-25 17:36:00 +02:00 committed by Hermet Park
parent 78bb8d1f2e
commit 520d6e7bbd

View file

@ -2174,11 +2174,11 @@ static void _svgLoaderParserXmlOpen(SvgLoaderData* loader, const char* content,
if (attrs) {
//Find out the tag name starting from content till sz length
sz = attrs - content;
attrsLength = length - sz;
while ((sz > 0) && (isspace(content[sz - 1]))) sz--;
if ((unsigned)sz >= sizeof(tagName)) return;
strncpy(tagName, content, sz);
tagName[sz] = '\0';
attrsLength = length - sz;
}
if ((method = _findGroupFactory(tagName))) {
@ -2540,11 +2540,11 @@ static bool _svgLoaderParserForValidCheckXmlOpen(SvgLoaderData* loader, const ch
if (attrs) {
sz = attrs - content;
attrsLength = length - sz;
while ((sz > 0) && (isspace(content[sz - 1]))) sz--;
if ((unsigned)sz >= sizeof(tagName)) return false;
strncpy(tagName, content, sz);
tagName[sz] = '\0';
attrsLength = length - sz;
}
if ((method = _findGroupFactory(tagName))) {