Security
- A long
transformattribute could makeconvertTransform()take time
quadratic in its length: each pair of brackets rebuilt the whole string, and the
result was checked only afterwards, so 2 MB of brackets, which a 3 KB.svgz
file holds, keptsvg2rlg()busy for minutes (CWE-407, GHSA-43qg-v5jj-vw5c). It
is read in one pass now, with the same result. Thanks to @lanjianchun for the
report. - An
<image>that refers to a fragment of the document, withhref="#id", was
rendered again without the checks that<use>has had since 2.3.1: a cycle, such
as an<svg>that contains an<image>that refers to it, ended in
RecursionError, and a few<image>elements that refer to each other, each
level to the one before it twice, took time that doubled with every level, so
that 2 KB took hours (CWE-400, CWE-674, GHSA-cmj4-5g24-pp37, reported again as
GHSA-4fr5-v6hm-mwjg). A cycle is now skipped and an error is logged, and all
<image>targets count against the same budgets as<use>
(MAX_USE_EXPANSIONS,MAX_USE_CLONED_ELEMENTS). An<image>that refers to an
element that is not defined yet is skipped too, and not anAttributeError.
Thanks to @GeniusKangaroo and @john-lawniczak for the reports. - An image embedded as a
data:image/pngordata:image/jpegURI was opened by
Pillow with the decoder chosen from its bytes, not from its label, so a
PostScript file made it run Ghostscript, where that is installed, when the PDF
was drawn (CWE-20, CWE-94, GHSA-h5r7-mh88-vjm4). Such an image is now decoded as
a PNG or a JPEG only (DATA_URI_IMAGE_FORMATS), and anything else is refused
with theUnidentifiedImageErrorthat data that is not an image already got.
Thanks to @superbot-helper for the report.
Tooling and housekeeping
- CI runs PyPy 3.11 on Ubuntu 24.04 instead of
ubuntu-latest, which is Ubuntu
26.04 now: the PyPy wheel of lxml needslibxml2.so.2, and 26.04 doesn't have
it, so the PyPy job failed at import time. The other jobs follow
ubuntu-latest.
Fixed
- A gradient with
spreadMethod="reflect"or"repeat"is now repeated past
its ends, as in browsers; it was painted black there. Every other period is
back to front forreflect. An unknownspreadMethodispad, and so is a
gradient that would need more than 200 periods, or more than 10,000 stops in
all of them (#567). - The
stop-colorandstop-opacityof a gradient stop can now be set by a
CSS rule, such as the classes of the SVG that Illustrator exports
(.cls-1 { stop-color: #fff }); the stop was black. A<style>element
now applies to the whole document, including the elements before it, as in
browsers, and not only to the gradients in its<defs>: a shape that comes
before a<style>that styles it is no longer black (#558). stop-colorset tocurrentColorin a gradient stop no longer makes
svg2rlg()fail withAttributeError; it is thecolorof the stop, as in
browsers, or black when none is set (#559).hwb()colors of CSS Color 4 are now converted to sRGB, asoklch()and
oklab()are: they were not read and the shape was not drawn (#560).stop-colorandstop-opacityof a gradient stop can now usevar(), such as
thestop-color="var(--fill-0, #171D25)"that Figma writes: the stop was
black, and the gradient with it. Avar()without a value is as if the
property was not set.- A gradient that refers to another one with
hrefnow takes the geometry,
gradientUnitsandspreadMethodof that gradient when it does not set them
itself, as in browsers: it used its own defaults (x2="1",pad,
objectBoundingBox) and so a gradient set on the first one was lost (#563). - The
offsetof a gradient stop is now limited to 0 to 1 and to at least the
offset of the stop before it, as in browsers: a stop beyond the ends, such as
offset="150%", or before the previous one drew a different gradient (#564). - CSS font-size keywords such as
large,x-small,largerandsmaller,
in thefont-sizeattribute, instyleattributes and in thefont
shorthand, no longer makesvg2rlg()fail withValueError. Absolute
keywords use the CSS Fonts values for a 16pxmedium, andlargerand
smallerscale by 1.2 (#537). - Relative font sizes such as
70%,2emandlargerare now resolved
against the font size of the parent element, as in CSS, instead of the
default size, so<tspan font-size="70%">inside<g font-size="20">gets
14 and not 70 (#327, #538). - Color keywords and function names are now read regardless of case, as in
CSS:fill="White",stroke="RED",RGB(255, 0, 0)andcurrentcolorno
longer leave the shape without a fill or stroke (#541). - The CSS named colors
rebeccapurpleandlightgray, which ReportLab lacks,
are now read, anddarkseagreenis#8fbc8fas in CSS, not ReportLab's
#8fbc8b(#542). - The content of a nested
<svg>with aviewBoxis now drawn at the size
given by itswidthandheight; it was drawn at 75% of that before,
because the px-to-pt factor of the drawing was applied a second time to the
nested viewport (#540). - A
clip-pathgiven in astyleattribute or a CSS rule, or as a quoted or
spacedurl()such asurl("#clip"), now clips the element; only the
clip-path="url(#clip)"attribute did before. Illustrator's CSS exports and
svgo-optimized matplotlib charts set it in CSS (#544). - The hue of
hsl()andhsla()may now have a CSS angle unit:deg,grad,
radorturn.fill="hsl(120deg, 100%, 50%)"was drawn black instead of
green (#543). - A
light-dark()color, which draw.io writes in its SVG exports, is now read
as its first, light color, the one CSS uses when nocolor-schemeis set;
the shape lost its fill or stroke before (#546). var()is now read, infill,strokeand other values, as Figma and VS
Code write colors that a theme can change, such as
fill="var(--fill-0, #171D25)": it is the custom property of the element or
an ancestor, set in astyleattribute or a CSS rule, or else its fallback.
Such a value was not read and the shape was not drawn. A value that needs
more than 1000 replacements, or becomes longer than 100,000 characters, is
invalid, so a small SVG cannot make it take exponential time (#554).- An
<image>that references an SVG document now draws it in the viewport
given by itswidthandheight, with its ownpreserveAspectRatio, as
browsers and Inkscape do; the document was drawn at its own size, ignoring
the size of the<image>(#237, #547). fillandstrokeset tocurrentColorin another case, such as
currentcolor, or with!important, now use thecolorproperty; they were
drawn black (#548).width="auto"andheight="auto"on an<svg>, as Figma writes them, for
instance in the country flags of the ProtonVPN apps, are now read like a
missingwidthandheight, also on a root<svg>without aviewBox;
svg2rlg()failed withValueError: Can't convert 'auto' to length(#550).emandexlengths in the geometry of shapes, such aswidth="2em"or
r="1em", and in thewidthandheightof the root<svg>, now use the
font size of the element, as in CSS; they always used 16px before (#549).oklch()andoklab()colors of CSS Color 4, as in the social preview
images of react-window, are now converted to sRGB: they were not read and
the shape was not drawn (#555).- The
xandyof a<use>, and of an<image>that references SVG
content, are now read as lengths: with a unit, such asx="20px"or
y="1in", or as a percentage, the content was drawn at the origin before
(#551). - A
<clipPath>without any shape now clips its elements away, as in browsers,
instead of leaving them without a clip:clip-path="url(#clip)"of an empty
<clipPath>drew the whole element (#553). - A gradient with no extent, that is a linear gradient with both ends in the same
place or a radial gradient with a radius of 0, now paints the shape in the
color of its last stop, as in browsers; it was black or the first color (#569). - The
gradientTransformof a linear or radial gradient is now applied, with
translate,scale,rotate,skewX,skewYandmatrix, in the units of
the bounding box and in the user space, and it is taken from the gradient it
refers to byhref; it was ignored, so a gradient rotated by Figma or Illustrator
ran in the wrong direction. A radial gradient scaled by it is an ellipse. With
spreadMethodreflectorrepeat, the periods that cover the shape are counted
in the space of the gradient, and a transform that cannot be inverted, such as
scale(0), paints nothing, as in browsers (#568). - A percentage in the coordinates or radius of a gradient with
gradientUnits="userSpaceOnUse", such asx2="50%"orr="25%", is now a
percentage of the viewport, as in browsers: of the width forx1,x2,cxand
fx, of the height fory1,y2,cyandfy, and of the normalized diagonal
forr. It was read as a fraction, sox2="50%"was half a user unit long (#570). - The
preserveAspectRatioof a nested<svg>now aligns the viewBox to the top
foryMinand to the bottom foryMax, as in browsers; they were the other way
round (#571). - A radial gradient in the units of the bounding box on a shape that is not square
is now an ellipse, and a slanted linear one is skewed, as in browsers, because the
gradient is stretched with the bounding box; they were drawn as a circle, and with
the lines of equal color perpendicular to the axis (#572).