Summary
svglib can consume excessive CPU and memory when rendering an SVG whose nested <use> references repeatedly fan out into larger copied subtrees. An attacker may cause a denial of service if an application renders an attacker-controlled SVG without a non-default option that prevents the expansion; some xhtml2pdf workflows can reach the same renderer through embedded SVG images.
Affected context
The issue affects svglib's SVG renderer in releases before 2.3.1 when it processes nested <use> references. Direct cycles are rejected, but acyclic graphs with repeated fan-out can still cause exponential node expansion during rendering. Applications that pass untrusted SVG files to the renderer may be exposed; HTML-to-PDF workflows using xhtml2pdf may also be affected when embedded SVG images are rendered through this path.
Exploit preconditions
- Attack surface: An application or service that renders SVG files with svglib, directly or through a workflow such as xhtml2pdf.
- Required access: The ability to supply or influence an SVG that the application processes; authentication requirements depend on the application.
- Trigger point: Rendering an SVG containing nested
<use>references. - Why exploitation is possible: Acyclic references with repeated fan-out can cause recursively copied subtrees to grow exponentially, consuming resources before rendering completes.
Why this happens
The renderer recursively resolves <use> references and deep-copies referenced subtrees. Rejecting direct cycles does not bound the size or total work of an acyclic reference graph with repeated fan-out. This is an uncontrolled resource consumption weakness (CWE-400); the recursive reference expansion is also related to CWE-776, which concerns unbounded recursive references.
Potential impact
- Rendering may consume excessive CPU and memory.
- A rendering task or worker may become unresponsive or terminate.
- Applications that process attacker-supplied documents could experience degraded availability.
- Shared rendering services may have reduced capacity for other users or workloads.
General mitigation guidance
Defensive patterns include bounding the amount of work and memory allowed during SVG processing, limiting reference depth and total expanded nodes, and rejecting documents that exceed defined complexity limits. Where SVG rendering is not essential, a secure-by-default approach is to disable it or accept only simpler, constrained image formats. Treat uploaded and embedded SVG content as untrusted, isolate rendering in a resource-limited process, and run that process with only the privileges it needs.
How teams detect issues like this
- Use static analysis and code review to identify recursive SVG reference resolution, deep-copy operations, and rendering paths without depth, node-count, or resource limits.
- Review upload, HTML-to-PDF, and document-conversion pipelines to identify whether untrusted SVGs can reach the renderer.
- Apply policy checks requiring explicit limits or isolation for services that process complex user-controlled documents.
- Monitor rendering jobs for unusual CPU or memory growth, timeouts, and repeated worker failures.
- Automated code review tools may help flag recursive parsing and unbounded resource-consumption patterns.

