GHSA-555j-qj3j-c8jv: svglib: Exponential resource consumption via nested <use> references in svg2rlg
- Source:
- OSV.dev
- Published:
- Fetched:
- Updated:
- Affects:
- svglib
https://osv.dev/vulnerability/GHSA-555j-qj3j-c8jv ↗
svglib: Exponential resource consumption via nested references in svg2rlg # Summary `svg2rlg()` expands ` ` references without any limit on the total number of expansions. Only direct cycles are rejected (`CircularRefError`). A group containing N ` ` 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 ` ` variant of the XML "billion laughs" attack (the same class as librsvg CVE-2019-20446). # Details `SvgRenderer.renderUse()` in `src/svglib/svglib.py`: ```python 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 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 ` ` element and rendered. Any ` ` 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): ```xml ... 10 times ... ... 10 times ... ... ... 10 times ... ``` # Impact 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 conversion, report generation. Only the SVG document needs to be attacker-controlled; no non-default option is required. The same happens through `xhtml2pdf`, which depends on svglib to render SVG images. An HTML document containing ` ` passed to `pisa.CreatePDF()` triggers the expansion. HTML-to-PDF conversion of user-supplied content is a common use of xhtml2pdf in web applications. # Reproduction Minimal local PoC, non-destructive: ```python import io, time from svglib.svglib import svg2rlg def make(levels, fan=10): parts = [' ', ' '] for i in range(1, levels + 1): parts.append(f' ' + f' ' * fan + ' ') parts.append(f' ') return "".join(parts).encode() for levels in (3, 4, 5): d Affected: PyPI:svglib Fixed in: 2.3.1 References: https://github.com/deeplook/svglib/security/advisories/GHSA-555j-qj3j-c8jv https://nvd.nist.gov/vuln/detail/CVE-2026-132275 https://github.com/deeplook/svglib/commit/7380d3c3836940fd75f8e203fff80077b7d5a425 https://github.com/deeplook/svglib https://github.com/deeplook/svglib/releases/tag/v2.3.1