loader/svg: Check current graphics node that not closed

If any of the graphics nodes are not closed,
the graphics nodes between them are ignored.

related issue: https://github.com/thorvg/thorvg/issues/2210
This commit is contained in:
JunsuChoi 2024-04-22 18:59:59 +09:00 committed by Hermet Park
parent a1ffa039bb
commit 0d20eb71eb
2 changed files with 14 additions and 0 deletions

View file

@ -3198,6 +3198,14 @@ static void _svgLoaderParserXmlClose(SvgLoaderData* loader, const char* content)
}
}
for (unsigned int i = 0; i < sizeof(graphicsTags) / sizeof(graphicsTags[0]); i++) {
if (!strncmp(content, graphicsTags[i].tag, graphicsTags[i].sz - 1)) {
loader->currentGraphicsNode = nullptr;
loader->stack.pop();
break;
}
}
loader->level--;
}
@ -3264,6 +3272,11 @@ static void _svgLoaderParserXmlOpen(SvgLoaderData* loader, const char* content,
if (loader->stack.count > 0) parent = loader->stack.last();
else parent = loader->doc;
node = method(loader, parent, attrs, attrsLength, simpleXmlParseAttributes);
if (node && !empty) {
auto defs = _createDefsNode(loader, nullptr, nullptr, 0, nullptr);
loader->stack.push(defs);
loader->currentGraphicsNode = node;
}
} else if ((gradientMethod = _findGradientFactory(tagName))) {
SvgStyleGradient* gradient;
gradient = gradientMethod(loader, attrs, attrsLength);

View file

@ -560,6 +560,7 @@ struct SvgLoaderData
int level = 0;
bool result = false;
bool style = false;
SvgNode* currentGraphicsNode = nullptr;
};
struct Box