svg_loader: buflen arg used in the simpleXmlParseW3CAttribute()

While parsing the css internal style sheets the buflen has to be passed.
This commit is contained in:
Mira Grudzinska 2022-01-17 22:55:02 +01:00 committed by Hermet Park
parent c351391bd5
commit 482add35e9
3 changed files with 20 additions and 20 deletions

View file

@ -798,7 +798,7 @@ static bool _attrParseSvgNode(void* data, const char* key, const char* value)
} else if (!strcmp(key, "preserveAspectRatio")) {
if (!strcmp(value, "none")) doc->preserveAspect = false;
} else if (!strcmp(key, "style")) {
return simpleXmlParseW3CAttribute(value, 0, _parseStyleAttr, loader);
return simpleXmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader);
}
#ifdef THORVG_LOG_ENABLED
else if ((!strcmp(key, "x") || !strcmp(key, "y")) && fabsf(svgUtilStrtof(value, nullptr)) > FLT_EPSILON) {
@ -951,13 +951,13 @@ static void _handleDisplayAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node,
}
static SvgNode* _findCssStyleNode(const SvgNode* cssStyle, const char* title)
static SvgNode* _findCssStyleNode(const SvgNode* cssStyle, const char* title, SvgNodeType type)
{
if (!cssStyle) return nullptr;
auto child = cssStyle->child.data;
for (uint32_t i = 0; i < cssStyle->child.count; ++i, ++child) {
if (((*child)->id) && !strcmp((*child)->id, title)) return (*child);
if ((*child)->type == type && ((*child)->id) && !strcmp((*child)->id, title)) return (*child);
}
return nullptr;
@ -973,8 +973,8 @@ static void _handleCssClassAttr(SvgLoaderData* loader, SvgNode* node, const char
*cssClass = _copyId(value);
//TODO: works only if style was defined before it is used
if (auto cssNode = _findCssStyleNode(loader->cssStyle, *cssClass)) {
//TODO: check SVG2 stndard - should the geometric properties be copied?
if (auto cssNode = _findCssStyleNode(loader->cssStyle, *cssClass, node->type)) {
//TODO: check SVG2 standard - should the geometric properties be copied?
_copyAttr(node, cssNode, false);
}
}
@ -1054,7 +1054,7 @@ static bool _attrParseGNode(void* data, const char* key, const char* value)
SvgNode* node = loader->svgParse->node;
if (!strcmp(key, "style")) {
return simpleXmlParseW3CAttribute(value, 0, _parseStyleAttr, loader);
return simpleXmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader);
} else if (!strcmp(key, "transform")) {
node->transform = _parseTransformationMatrix(value);
} else if (!strcmp(key, "id")) {
@ -1083,7 +1083,7 @@ static bool _attrParseClipPathNode(void* data, const char* key, const char* valu
SvgClipNode* clip = &(node->node.clip);
if (!strcmp(key, "style")) {
return simpleXmlParseW3CAttribute(value, 0, _parseStyleAttr, loader);
return simpleXmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader);
} else if (!strcmp(key, "transform")) {
node->transform = _parseTransformationMatrix(value);
} else if (!strcmp(key, "id")) {
@ -1107,7 +1107,7 @@ static bool _attrParseMaskNode(void* data, const char* key, const char* value)
SvgMaskNode* mask = &(node->node.mask);
if (!strcmp(key, "style")) {
return simpleXmlParseW3CAttribute(value, 0, _parseStyleAttr, loader);
return simpleXmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader);
} else if (!strcmp(key, "transform")) {
node->transform = _parseTransformationMatrix(value);
} else if (!strcmp(key, "id")) {
@ -1286,7 +1286,7 @@ static bool _attrParsePathNode(void* data, const char* key, const char* value)
//Temporary: need to copy
path->path = _copyId(value);
} else if (!strcmp(key, "style")) {
return simpleXmlParseW3CAttribute(value, 0, _parseStyleAttr, loader);
return simpleXmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader);
} else if (!strcmp(key, "clip-path")) {
_handleClipPathAttr(loader, node, value);
} else if (!strcmp(key, "mask")) {
@ -1348,7 +1348,7 @@ static bool _attrParseCircleNode(void* data, const char* key, const char* value)
}
if (!strcmp(key, "style")) {
return simpleXmlParseW3CAttribute(value, 0, _parseStyleAttr, loader);
return simpleXmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader);
} else if (!strcmp(key, "clip-path")) {
_handleClipPathAttr(loader, node, value);
} else if (!strcmp(key, "mask")) {
@ -1415,7 +1415,7 @@ static bool _attrParseEllipseNode(void* data, const char* key, const char* value
} else if (!strcmp(key, "class")) {
_handleCssClassAttr(loader, node, value);
} else if (!strcmp(key, "style")) {
return simpleXmlParseW3CAttribute(value, 0, _parseStyleAttr, loader);
return simpleXmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader);
} else if (!strcmp(key, "clip-path")) {
_handleClipPathAttr(loader, node, value);
} else if (!strcmp(key, "mask")) {
@ -1489,7 +1489,7 @@ static bool _attrParsePolygonNode(void* data, const char* key, const char* value
if (!strcmp(key, "points")) {
return _attrParsePolygonPoints(value, &polygon->points, &polygon->pointsCount);
} else if (!strcmp(key, "style")) {
return simpleXmlParseW3CAttribute(value, 0, _parseStyleAttr, loader);
return simpleXmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader);
} else if (!strcmp(key, "clip-path")) {
_handleClipPathAttr(loader, node, value);
} else if (!strcmp(key, "mask")) {
@ -1576,7 +1576,7 @@ static bool _attrParseRectNode(void* data, const char* key, const char* value)
} else if (!strcmp(key, "class")) {
_handleCssClassAttr(loader, node, value);
} else if (!strcmp(key, "style")) {
ret = simpleXmlParseW3CAttribute(value, 0, _parseStyleAttr, loader);
ret = simpleXmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader);
} else if (!strcmp(key, "clip-path")) {
_handleClipPathAttr(loader, node, value);
} else if (!strcmp(key, "mask")) {
@ -1641,7 +1641,7 @@ static bool _attrParseLineNode(void* data, const char* key, const char* value)
} else if (!strcmp(key, "class")) {
_handleCssClassAttr(loader, node, value);
} else if (!strcmp(key, "style")) {
return simpleXmlParseW3CAttribute(value, 0, _parseStyleAttr, loader);
return simpleXmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader);
} else if (!strcmp(key, "clip-path")) {
_handleClipPathAttr(loader, node, value);
} else if (!strcmp(key, "mask")) {
@ -1714,7 +1714,7 @@ static bool _attrParseImageNode(void* data, const char* key, const char* value)
} else if (!strcmp(key, "class")) {
_handleCssClassAttr(loader, node, value);
} else if (!strcmp(key, "style")) {
return simpleXmlParseW3CAttribute(value, 0, _parseStyleAttr, loader);
return simpleXmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader);
} else if (!strcmp(key, "clip-path")) {
_handleClipPathAttr(loader, node, value);
} else if (!strcmp(key, "mask")) {
@ -2390,7 +2390,7 @@ static bool _attrParseStops(void* data, const char* key, const char* value)
_toColor(value, &stop->r, &stop->g, &stop->b, nullptr);
}
} else if (!strcmp(key, "style")) {
simpleXmlParseW3CAttribute(value, 0, _attrParseStopsStyle, data);
simpleXmlParseW3CAttribute(value, strlen(value), _attrParseStopsStyle, data);
} else {
return false;
}
@ -2717,6 +2717,7 @@ static void _svgLoaderParserXmlStyle(SvgLoaderData* loader, const char* content,
buflen -= next - buf;
buf = next;
free(tag);
free(name);
}

View file

@ -450,7 +450,7 @@ bool simpleXmlParse(const char* buf, unsigned bufLength, bool strip, simpleXMLCb
}
bool simpleXmlParseW3CAttribute(const char* buf, TVG_UNUSED unsigned buflen, simpleXMLAttributeCb func, const void* data)
bool simpleXmlParseW3CAttribute(const char* buf, unsigned buflen, simpleXMLAttributeCb func, const void* data)
{
const char* end;
char* key;
@ -459,7 +459,7 @@ bool simpleXmlParseW3CAttribute(const char* buf, TVG_UNUSED unsigned buflen, sim
if (!buf) return false;
end = buf + strlen(buf);
end = buf + buflen;
key = (char*)alloca(end - buf + 1);
val = (char*)alloca(end - buf + 1);
@ -475,7 +475,6 @@ bool simpleXmlParseW3CAttribute(const char* buf, TVG_UNUSED unsigned buflen, sim
}
if (next >= end) next = nullptr;
key[0] = '\0';
val[0] = '\0';

View file

@ -49,7 +49,7 @@ typedef bool (*simpleXMLAttributeCb)(void* data, const char* key, const char* va
bool simpleXmlParseAttributes(const char* buf, unsigned buflen, simpleXMLAttributeCb func, const void* data);
bool simpleXmlParse(const char* buf, unsigned buflen, bool strip, simpleXMLCb func, const void* data);
bool simpleXmlParseW3CAttribute(const char* buf, TVG_UNUSED unsigned buflen, simpleXMLAttributeCb func, const void* data);
bool simpleXmlParseW3CAttribute(const char* buf, unsigned buflen, simpleXMLAttributeCb func, const void* data);
const char* simpleXmlParseCSSAttribute(const char* buf, unsigned bufLength, char** tag, char** name, const char** attrs, unsigned* attrsLength);
const char* simpleXmlFindAttributesTag(const char* buf, unsigned buflen);
bool isIgnoreUnsupportedLogElements(const char* tagName);