loading inline SVG data as input from pygobject bindings panics
The following Python 3 snippet using the GObject Introspection bindings
import gi
gi.require_version("Rsvg", "2.0")
from gi.repository import Gio, Rsvg, GLib
ICON = b"""
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="64px" viewBox="0 0 64 64" version="1.1" height="64px" enable-background="new 0 0 64 64">
<circle style="fill:#e0995e" id="circle86" r="32" cy="32" cx="32"/>
<path d="m 45.5,33.167 h -5 v -7.334 c 0,-4.687 -3.813,-8.5 -8.5,-8.5 -4.687,0 -8.5,3.813 -8.5,8.5 v 7.334 h -5 v -7.334 c 0,-7.444 6.056,-13.5 13.5,-13.5 7.444,0 13.5,6.056 13.5,13.5 z" id="path90" style="fill:#231f20"/>
<path style="fill:#4f5d73" id="path96" d="m 45.5,31.167 h -5 v -7.334 c 0,-4.687 -3.813,-8.5 -8.5,-8.5 -4.687,0 -8.5,3.813 -8.5,8.5 v 7.334 h -5 v -7.334 c 0,-7.444 6.056,-13.5 13.5,-13.5 7.444,0 13.5,6.056 13.5,13.5 z"/>
<path d="m 32,32 c -2.209,0 -4,1.791 -4,4 0,1.477 0.809,2.752 2,3.445 V 42 c 0,1.105 0.895,2 2,2 1.105,0 2,-0.895 2,-2 v -2.555 c 1.191,-0.693 2,-1.968 2,-3.445 0,-2.209 -1.791,-4 -4,-4 z" id="path100" style="fill:#4f5d73"/>
<path style="fill:#231f20" id="path106" d="M 47,27 H 17 c -1.657,0 -3,1.343 -3,3 v 19 c 0,1.657 1.343,3 3,3 h 30 c 1.657,0 3,-1.343 3,-3 V 30 c 0,-1.657 -1.343,-3 -3,-3 z M 34,41.445 V 44 c 0,1.105 -0.895,2 -2,2 -1.105,0 -2,-0.895 -2,-2 V 41.445 C 28.809,40.752 28,39.477 28,38 c 0,-2.209 1.791,-4 4,-4 2.209,0 4,1.791 4,4 0,1.477 -0.809,2.752 -2,3.445 z"/>
<path style="fill:#ffffff" id="path110" d="M 47,25 H 17 c -1.657,0 -3,1.343 -3,3 v 19 c 0,1.657 1.343,3 3,3 h 30 c 1.657,0 3,-1.343 3,-3 V 28 c 0,-1.657 -1.343,-3 -3,-3 z M 34,39.445 V 42 c 0,1.105 -0.895,2 -2,2 -1.105,0 -2,-0.895 -2,-2 V 39.445 C 28.809,38.752 28,37.477 28,36 c 0,-2.209 1.791,-4 4,-4 2.209,0 4,1.791 4,4 0,1.477 -0.809,2.752 -2,3.445 z"/>
</svg>"""
stream = Gio.MemoryInputStream.new_from_bytes(GLib.Bytes(ICON))
svg = Rsvg.Handle.new_from_stream_sync(stream, None, Rsvg.HandleFlags.FLAG_UNLIMITED, None)
This is the backtrace:
thread '<unnamed>' panicked at 'characters: XML handler stack is empty!?', rsvg_internals/src/xml.rs:185:31
stack backtrace:
0: <unknown>
1: <unknown>
2: <unknown>
3: <unknown>
4: <unknown>
5: <unknown>
6: <unknown>
7: xmlParseCharData
8: xmlParseContent
9: xmlParseElement
10: xmlParseDocument
11: <unknown>
12: <unknown>
13: <unknown>
14: <unknown>
15: <unknown>
16: ffi_call_unix64
17: ffi_call
18: <unknown>
19: <unknown>
20: <unknown>
21: <unknown>
22: _PyObject_FastCallKeywords
23: <unknown>
24: _PyEval_EvalFrameDefault
25: _PyEval_EvalCodeWithName
26: PyEval_EvalCodeEx
27: PyEval_EvalCode
28: <unknown>
29: PyRun_FileExFlags
30: PyRun_SimpleFileExFlags
31: <unknown>
32: _Py_UnixMain
33: __libc_start_main
34: _start
fatal runtime error: failed to initiate panic, error 5
Aborted (core dumped)