Exception "The SVG size is undefined" raised using svg2png

Open
#440 1 comment 1 reaction 0 assignees View on GitHub

@DSeaStar is already working on this.

Since Aug 14, 2026.

  • #455 by @DSeaStar — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python

Research direction

Start with the provided Python script and SVG URL, reproducing the failure through cairosvg.svg2png. Trace the reported path in cairosvg/surface.py around SVGSurface and mask handling, then add a regression test for this input; done means the SVG converts to PNG without the reported exception.

Written by the indexing model from the issue text.

Description

bug

Converting the following SVG file (see code bellow) into a PNG caused an exception to be raised:

Traceback (most recent call last):
  File "/Volumes/Test/main.py", line 12, in <module>
    cairosvg.svg2png(url=URL, write_to=OUTPUT_PATH)
  File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/__init__.py", line 55, in svg2png
    return surface.PNGSurface.convert(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/surface.py", line 133, in convert
    instance = cls(
               ^^^^
  File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/surface.py", line 225, in __init__
    self.draw(tree)
  File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/surface.py", line 472, in draw
    self.draw(child)
  File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/surface.py", line 472, in draw
    self.draw(child)
  File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/surface.py", line 480, in draw
    paint_mask(self, node, mask, opacity)
  File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/defs.py", line 145, in paint_mask
    mask_surface = SVGSurface(mask_node, None, surface.dpi, surface)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/surface.py", line 209, in __init__
    raise ValueError('The SVG size is undefined')
ValueError: The SVG size is undefined

Here is the code to reproduce:

import cairosvg

URL = "https://upload.wikimedia.org/wikipedia/commons/3/32/Saltwater_Limpet_Diagram-en.svg"
OUTPUT_PATH = "output.png"
cairosvg.svg2png(url=URL, write_to=OUTPUT_PATH)
Dominant language
Python
Stars
959
Forks
172
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Kozea/CairoSVG

All issues in Kozea/CairoSVG

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.