---
schema_version: '1.0'
id: security-20261016-0a4c15
title: 'CVE-2026-107378: CairoSVG: Quadratic-time DoS parsing a crafted SVG <path>'
url: https://osv.dev/vulnerability/PYSEC-2026-4204
url_hash: 0a4c1532627e487b2e67f925978dc7cd9e5ca50a690ec6a993c024f3837f3c29
canonical_url: https://osv.dev/vulnerability/PYSEC-2026-4204
source: osv:pypa
category: security/library
category_raw: cve/library
region: null
tags:
- cve
- CVE-2026-107378
- PYSEC-2026-4204
- severity:CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
- cairosvg
- PyPI
lang: en
published_at: '2026-10-15T10:22:52Z'
fetched_at: '2026-10-16T11:21:45.164103Z'
updated_at: '2026-10-16T13:02:16Z'
status: published
content_hash: 29f4a973f48ff56d9cadd39a094d0fe66c3f8a3d23d9ca8a18960d991f502169
content_changed_at: null
license_note: full
summary: 'CairoSVG: Quadratic-time DoS parsing a crafted SVG <path>'
summary_source: rss
summary_en: 'CairoSVG: Quadratic-time DoS parsing a crafted SVG <path>'
summary_omitted_reason: null
redistribution: true
keywords_en:
- CairoSVG
- crafted
- cve
- CVE-2026-107378
- DoS
- library vulnerability
- Mrs Oladosu
- parsing
- path
- PyPI
- PYSEC-2026-4204
- Quadratic-time
- severity:CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
- software security
- SVG
entities_en:
- name: CairoSVG
  type: artifact
- name: Mrs Oladosu
  type: 人
topics_en:
- library vulnerability
- software security
numeric_facts: []
entities:
- name: CairoSVG
  type: artifact
- name: Mrs Oladosu
  type: 人
key_facts: []
related: []
related_auto: []
computed_at: '2026-10-16T13:02:07Z'
---

# CVE-2026-107378: CairoSVG: Quadratic-time DoS parsing a crafted SVG <path>

## TL;DR
CairoSVG: Quadratic-time DoS parsing a crafted SVG <path>

## Key Points
- cve / CVE-2026-107378 / PYSEC-2026-4204 / severity:CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N / cairosvg / PyPI

## Details
**Severity:** CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
**Advisory:** PYSEC-2026-4204 (CVE-2026-107378)

**Details:**
## Summary

Rendering an untrusted SVG whose `<path d="...">` contains many segments is O(n²) CPU. A single `<path>` under 1 MiB burns tens of seconds. Two independent O(n²) sites in `cairosvg/path.py`:

1. **Tokenizer** — the path-data parser consumes the `d` string with a `while string:` loop that repeatedly slices/re-scans the *remaining* string (each step is O(len remaining)), giving O(n²) over the whole attribute.
2. **draw_markers** — marker handling drains `node.vertices` with `while node.vertices: ... node.vertices.pop(0)`; `list.pop(0)` is O(n), so draining n vertices is O(n²).

Both are hit on a normal render path (`svg2png`/`svg2pdf`), attacker controls only the SVG document.

## PoC (installed cairosvg 2.9.0)

```python
import cairosvg
d = "M0 0 " + "L1 1 " * 100000
svg = f'<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><path d="{d}"/></svg>'
cairosvg.svg2png(bytestring=svg.encode())   # ~4.4 s for a 488 KB doc
```

| path segments | SVG size | time |
|---|---|---|
| 50,000 | 244 KB | 1.14 s |
| 100,000 | 488 KB | 4.36 s |
| 200,000 | ~960 KB | ~18 s |

Doubling segments ≈ 4× time ⇒ quadratic. Sub-MiB input ⇒ ~18 s CPU; any service rendering user-supplied SVG (thumbnails, avatars, PDF export) is a DoS target.

## Reachability

Public API `svg2png` / `svg2pdf` / `svg2ps` on an untrusted SVG string.

## Suggested fix

Tokenize with a single forward scan / index (or `re.finditer`) instead of re-slicing the remainder; drain `vertices` with an index or `collections.deque.popleft` instead of `list.pop(0)`. Optionally cap path-segment count.

**References:**
- https://github.com/Kozea/CairoSVG/security/advisories/GHSA-c3jg-qh8m-j3h2
- https://nvd.nist.gov/vuln/detail/CVE-2026-107378
- https://github.com/Kozea/CairoSVG/commit/9d63f049f9988d0ddda3eb94564ac3a50a286523
- https://github.com/Kozea/CairoSVG/commit/a4d585eb374724b79676e9cceaa9e9a1a4358565
- https://github.com/Kozea/CairoSVG
- https://github.com/Kozea/CairoSVG/releases/tag/2.9.1
- https://pypi.org/project/cairosvg
- https://github.com/advisories/GHSA-c3jg-qh8m-j3h2

_Data: OSV.dev (upstream: pypa) — https://osv.dev/vulnerability/PYSEC-2026-4204_

## Source
元記事: [CVE-2026-107378: CairoSVG: Quadratic-time DoS parsing a crafted SVG <path>](https://osv.dev/vulnerability/PYSEC-2026-4204) — published 2026-10-15T10:22:52Z
