Abort in rsvg with 'Cairo error "invalid matrix (not invertible)"' when trying to render certain broken svgs
When I try to render an svg file like this with rsvg (versions 2.41.0-2.42.0):
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="10" height="10">
<defs>
<linearGradient id="grad"/>
<g id="path">
<path d=""/>
</g>
</defs>
<g>
<use style="fill:url(#grad)" xlink:href="#path"/>
</g>
</svg>
I get:
% rsvg-convert error_empty_path.svg -o error_empty_path.png
thread '<unnamed>' panicked at 'Cairo error "invalid matrix (not invertible)"', /build/.cargo/registry/src/github.com-1ecc6299db9ec823/cairo-sys-rs-0.5.0/src/enums.rs:75:12
note: Run with `RUST_BACKTRACE=1` for a backtrace.
fatal runtime error: failed to initiate panic, error 5
zsh: abort (core dumped) rsvg-convert error_empty_path.svg -o error_empty_path.png
The same happens, when the path is a degenerate triangle:
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="10" height="10">
<defs>
<linearGradient id="grad"/>
<g id="path">
<path d="M0,0L1,1L2,2Z"/>
</g>
</defs>
<g>
<use style="fill:url(#grad)" xlink:href="#path"/>
</g>
</svg>
gives:
% rsvg-convert error_not_triangle.svg -o error_not_triangle.png
thread '<unnamed>' panicked at 'Cairo error "invalid matrix (not invertible)"', /build/.cargo/registry/src/github.com-1ecc6299db9ec823/cairo-sys-rs-0.5.0/src/enums.rs:75:12
note: Run with `RUST_BACKTRACE=1` for a backtrace.
fatal runtime error: failed to initiate panic, error 5
zsh: abort (core dumped) rsvg-convert error_not_triangle.svg -o error_not_triangle.png
However, when the path is a proper triangle:
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="10" height="10">
<defs>
<linearGradient id="grad"/>
<g id="path">
<path d="M0,0L1,1L1,2Z"/>
</g>
</defs>
<g>
<use style="fill:url(#grad)" xlink:href="#path"/>
</g>
</svg>
no error is shown.
Version 2.40.20 doesn't have such issue (yielding empty 10x10 pngs in all cases).
I stumbled across this issue because an SVG icon set (ACYLS) contains such broken SVGs and it causes programs, that try to display those icons to fail with the above abort.
Now, I know those SVG files are broken and wouldn't render anything useful anyway, but I think the library shouldn't abort, and with a cryptic message (the message doesn't indicate the cause of the problem and it took me a while to find that cause). What I'd expect ideally is for the library to return an empty image and display a warning in the console, and allow the application to continue.
All 3 minimal example files are attached. Please be weary that if you have librsvg between 2.41.0-2.42.0 installed, these files can kill any program that will try to render them (I had firefox crash when I tried to attach them here for this reason).