Package: release.debian.org
Severity: normal
Tags: trixie
X-Debbugs-Cc: [email protected]
Control: affects -1 + src:cairosvg
User: [email protected]
Usertags: pu

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

[ Reason ]
CVE-2026-31899
CVE-2026-107378

[ Impact ]
These vulns can cause a denial of service via CPU exhaustion when a
malicious SVG file is passed to cairosvg.

[ Tests ]
Upstream testsuite continues to pass during dh_auto_test and
autopkgtest. Smoke testing in a trixie VM has had no issues or changes
in behaviour.

I verified that the patch for CVE-2026-107378 fixes the issue using the
POC from
https://github.com/Kozea/CairoSVG/security/advisories/GHSA-c3jg-qh8m-j3h2
before and after.

I was unable to verify the effectiveness of the patch for CVE-2026-31899
using the POC from
https://github.com/Kozea/CairoSVG/security/advisories/GHSA-f38f-5xpm-9r7c
since cairosvg currently in trixie will say "ValueError: The SVG size is
undefined", and when width & height parameters are added to the SVG, it
appears unaffected by the issue (no timeout). The behaviour is the same
with the patched package as well.

[ Risks ]
Patches are minimal and targetted, and are straight from upstream
without any changes, so low risk.

[ Checklist ]
  [x] *all* changes are documented in the d/changelog
  [x] I reviewed all changes and I approve them
  [x] attach debdiff against the package in (old)stable
  [x] the issue is verified as fixed in unstable

[ Changes ]
  * Add patch for CVE-2026-31899
    This patch prevents the exponential DOS by putting a hard limit of
    100,000 on the amount of referenced elements rendered.
  * Add patch for CVE-2026-107378
    Change .pop(0) for .popleft() and use regex-based tokenizer instead
    of string.split() to avoid quadratic complexity.

[ Other info ]
N/A

- --
Maytham

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEESl/RzRFQh8wD3DXB1ZeJcgbF8H8FAmsQkLsACgkQ1ZeJcgbF
8H9mIQ//RhrezacIUvFYLGC/TA8U1kb83mlzmNy9/XN17CDXiz+F3IhJ7eP58sN6
ao8DjgM5qldw2BpDeAos9i45tz3OyE7MfhKo6soiaXYKVBbtrZeNm/+bMzgBSO1R
8FSSzr4MLv6+ZvU59Z0332DR2x17FAhIUuQdAXi/sB7jujpkErv9fr8pvqs+6W4I
pkFZEw9Kp8otsfCaNncqNLqx4Y6D7LQfBOkLGgah4Lu4RwYwyBBOD1N5A2Y4Yhx9
OpyJKuOmPkfqTcILLTi5+cz4/qNbFeMioDJm5uSLWUeWNSJxKgQ9E/IBPHrVsBCp
Pyrwew+tDQXSQm4B6pA8dIvrGhZs6Iu93Qx5SGqAjDkL7YtcRyyM8IEU2hPl1Yax
7NvNc8/hbZe0xbrI9Qb2NzDEY6RrbTVvhlpC3PpUiXuo3w7joxDMnXrHpur0UT+v
zw9XSNqah3GEaWkIVmVWKZ7MusjEMB4yhDchluh8bVAxCc17IMyseiCWqmxRbppW
2K612I5G/5aMD75RLwvmEtsw3Vr/pcN6e/JcbV2dXfntx0YYXUJyXJKQm9yUzlqH
rGcQLCqYD8HBu5Exjp5E4SwSzusnXQ9JEFBWfigOsBeJcuvC8MrUxIEGUGUJW1L2
Yv5D+1rCPZCol38TYR9wA3MCwVZOPpp3FDG/L5idV7mwJLcVEEw=
=YLMO
-----END PGP SIGNATURE-----
diff -Nru cairosvg-2.7.1/debian/changelog cairosvg-2.7.1/debian/changelog
--- cairosvg-2.7.1/debian/changelog     2025-04-17 08:21:50.000000000 +0800
+++ cairosvg-2.7.1/debian/changelog     2026-12-02 16:55:38.000000000 +0800
@@ -1,3 +1,10 @@
+cairosvg (2.7.1-2+deb13u1) trixie; urgency=medium
+
+  * Add patch for CVE-2026-31899
+  * Add patch for CVE-2026-107378
+
+ -- Maytham Alsudany <[email protected]>  Wed, 02 Dec 2026 16:55:38 +0800
+
 cairosvg (2.7.1-2) unstable; urgency=medium
 
   * Team upload.
diff -Nru cairosvg-2.7.1/debian/patches/CVE-2026-107378.patch 
cairosvg-2.7.1/debian/patches/CVE-2026-107378.patch
--- cairosvg-2.7.1/debian/patches/CVE-2026-107378.patch 1970-01-01 
08:00:00.000000000 +0800
+++ cairosvg-2.7.1/debian/patches/CVE-2026-107378.patch 2026-12-02 
16:55:38.000000000 +0800
@@ -0,0 +1,123 @@
+From a4d585eb374724b79676e9cceaa9e9a1a4358565 Mon Sep 17 00:00:00 2001
+From: Guillaume Ayoub <[email protected]>
+Date: Wed, 12 Aug 2026 09:18:02 +0200
+Subject: [PATCH] Don’t use O(n) list.pop(0) for vertices, use O(1) 
deque.popleft()
+
+From 9d63f049f9988d0ddda3eb94564ac3a50a286523 Mon Sep 17 00:00:00 2001
+From: Guillaume Ayoub <[email protected]>
+Date: Wed, 12 Aug 2026 10:25:56 +0200
+Subject: [PATCH] Use a regex-based tokenizer for paths to avoid quadratic
+ compexity
+
+--- a/cairosvg/path.py
++++ b/cairosvg/path.py
+@@ -3,7 +3,9 @@
+ 
+ """
+ 
++from collections import deque
+ from math import pi, radians
++from re import finditer
+ 
+ from .bounding_box import calculate_bounding_box
+ from .helpers import (
+@@ -31,8 +33,8 @@
+ 
+     while node.vertices:
+         # Calculate position and angle
+-        point = node.vertices.pop(0)
+-        angles = node.vertices.pop(0) if node.vertices else None
++        point = node.vertices.popleft()
++        angles = node.vertices.popleft() if node.vertices else None
+         if angles:
+             if position == 'start':
+                 angle = pi - angles[0]
+@@ -122,7 +124,7 @@
+     """Draw a path ``node``."""
+     string = node.get('d', '')
+ 
+-    node.vertices = []
++    node.vertices = deque()
+ 
+     for letter in PATH_LETTERS:
+         string = string.replace(letter, f' {letter} ')
+@@ -138,17 +140,14 @@
+         surface.context.move_to(0, 0)
+         current_point = 0, 0
+ 
+-    while string:
++    matches = deque(match.groups() for match in finditer(
++         f'([{PATH_LETTERS}])([^{PATH_LETTERS}]*)', string.strip()))
++    while matches:
++        letter, string = matches.popleft()
+         string = string.strip()
+-        if string.split(' ', 1)[0] in PATH_LETTERS:
+-            letter, string = (string + ' ').split(' ', 1)
+-            if last_letter in (None, 'z', 'Z') and letter not in 'mM':
+-                node.vertices.append(current_point)
+-                first_path_point = current_point
+-        elif letter == 'M':
+-            letter = 'L'
+-        elif letter == 'm':
+-            letter = 'l'
++        if last_letter in (None, 'z', 'Z') and letter not in 'mM':
++            node.vertices.append(current_point)
++            first_path_point = current_point
+ 
+         if last_letter in (None, 'm', 'M', 'z', 'Z'):
+             first_path_point = None
+@@ -186,14 +185,12 @@
+ 
+             # rx=0 or ry=0 means straight line
+             if not rx or not ry:
+-                if string and string[0] not in PATH_LETTERS:
++                if string := string.strip():
+                     # As we replace the current operation by l, we must be 
sure
+                     # that the next letter is set to the real current letter 
(a
+                     # or A) in case it’s omitted
+-                    next_letter = f'{letter} '
+-                else:
+-                    next_letter = ''
+-                string = f'l {x3} {y3} {next_letter}{string}'
++                    matches.appendleft((letter, string))
++                matches.appendleft(('l', f'{x3} {y3}'))
+                 continue
+ 
+             radii_ratio = ry / rx
+@@ -448,5 +445,7 @@
+         if letter not in 'zZ':
+             node.vertices.append(current_point)
+ 
+-        string = string.strip()
++        if string := string.strip():
++            next_letter = {'m': 'l', 'M': 'L'}.get(letter, letter)
++            matches.appendleft((next_letter, string))
+         last_letter = letter
+--- a/cairosvg/shapes.py
++++ b/cairosvg/shapes.py
+@@ -3,6 +3,7 @@
+ 
+ """
+ 
++from collections import deque
+ from math import pi
+ 
+ from .helpers import normalize, point, point_angle, size
+@@ -45,7 +46,7 @@
+     surface.context.move_to(x1, y1)
+     surface.context.line_to(x2, y2)
+     angle = point_angle(x1, y1, x2, y2)
+-    node.vertices = [(x1, y1), (pi - angle, angle), (x2, y2)]
++    node.vertices = deque([(x1, y1), (pi - angle, angle), (x2, y2)])
+ 
+ 
+ def polygon(surface, node):
+@@ -60,7 +61,7 @@
+     if points:
+         x, y, points = point(surface, points)
+         surface.context.move_to(x, y)
+-        node.vertices = [(x, y)]
++        node.vertices = deque([(x, y)])
+         while points:
+             x_old, y_old = x, y
+             x, y, points = point(surface, points)
diff -Nru cairosvg-2.7.1/debian/patches/CVE-2026-31899.patch 
cairosvg-2.7.1/debian/patches/CVE-2026-31899.patch
--- cairosvg-2.7.1/debian/patches/CVE-2026-31899.patch  1970-01-01 
08:00:00.000000000 +0800
+++ cairosvg-2.7.1/debian/patches/CVE-2026-31899.patch  2026-12-02 
16:55:38.000000000 +0800
@@ -0,0 +1,37 @@
+From 6dde8685ed3f19837767bce7a13a5491e3d0e0bf Mon Sep 17 00:00:00 2001
+From: Guillaume Ayoub <[email protected]>
+Date: Tue, 10 Mar 2026 14:39:15 +0100
+Subject: [PATCH] Abort when more than 100k referenced elements are rendered
+
+This avoid exponential complexity with nested use tags.
+---
+ cairosvg/defs.py    | 3 +++
+ cairosvg/surface.py | 1 +
+ 2 files changed, 4 insertions(+)
+
+diff --git a/cairosvg/defs.py b/cairosvg/defs.py
+index 9c74876b..d25e7810 100644
+--- a/cairosvg/defs.py
++++ b/cairosvg/defs.py
+@@ -334,6 +334,9 @@ def apply_filter_after_painting(surface, node, name):
+ 
+ def use(surface, node):
+     """Draw the content of another SVG node."""
++    surface.reference_count += 1
++    if not node.unsafe and surface.reference_count > 100_000:
++        raise ValueError('Abort rendering: more than 100 000 referenced 
elements')
+     surface.context.save()
+     surface.context.translate(
+         size(surface, node.get('x'), 'x'), size(surface, node.get('y'), 'y'))
+diff --git a/cairosvg/surface.py b/cairosvg/surface.py
+index 2f29236c..15d6b069 100644
+--- a/cairosvg/surface.py
++++ b/cairosvg/surface.py
+@@ -163,6 +163,7 @@ def __init__(self, tree, output, dpi, parent_surface=None,
+         self.cursor_d_position = [0, 0]
+         self.text_path_width = 0
+         self.tree_cache = {(tree.url, tree.get('id')): tree}
++        self.reference_count = 0
+         if parent_surface:
+             self.markers = parent_surface.markers
+             self.gradients = parent_surface.gradients
diff -Nru cairosvg-2.7.1/debian/patches/series 
cairosvg-2.7.1/debian/patches/series
--- cairosvg-2.7.1/debian/patches/series        2025-04-17 08:21:50.000000000 
+0800
+++ cairosvg-2.7.1/debian/patches/series        2026-12-02 16:55:38.000000000 
+0800
@@ -1,2 +1,4 @@
 0001-Remove-pytest-options-for-plugins-not-packaged-for-D.patch
 setup.cfg-underscore.patch
+CVE-2026-31899.patch
+CVE-2026-107378.patch

Reply via email to