svg2rlg() expands <use> references without any limit on the total number of expansions. Only direct cycles are rejected (CircularRefError). A group containing N <use> elements that point to another such group multiplies the work by N per nesting level, so an SVG of about 1.4 KB makes svglib clone and render over 100,000 nodes, taking tens of seconds of CPU time and hundreds of MiB of memory. Each additional level adds about 245 bytes to the document and multiplies time by ~10.
This is the SVG <use> variant of the XML "billion laughs" attack (the same class as librsvg CVE-2019-20446).
SvgRenderer.renderUse() in src/svglib/svglib.py:
try:
item = self.xlink_href_target(node, group=group)
except CircularRefError:
node.parent.etree_element.remove(node.etree_element)
return group
...
if len(node.getchildren()) == 0:
# Append a copy of the referenced node as the <use> child (if not
# already done)
node.append(copy.deepcopy(item))
self.renderNode(list(node.iter_children())[-1], parent=group)
The referenced node is deep-copied under the <use> element and rendered. Any <use> elements inside the copied subtree go through renderUse() again. xlink_href_target() raises CircularRefError only for a direct cycle, so a reference DAG with fan-out is expanded fully: fan ** levels renders.
Payload shape (fan = 10, levels = 5):
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="10" height="10">
<defs>
<rect id="l0" width="1" height="1"/>
<g id="l1"><use xlink:href="#l0"/> ... 10 times ... </g>
<g id="l2"><use xlink:href="#l1"/> ... 10 times ... </g>
...
<g id="l5"><use xlink:href="#l4"/> ... 10 times ... </g>
</defs>
<use xlink:href="#l5"/>
</svg>
Denial of service (CPU and memory exhaustion) for any application that renders SVG from an untrusted source with svglib: thumbnail/preview generation, SVG-to-PDF...
2.3.1Exploitability
AV:NAC:LPR:NUI:NScope
S:UImpact
C:NI:NA:H7.5/CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:HOther
Resource Management