libxml2-python segfault after doc.freeDoc()
Use repro.py with tst.xml and then run:
matej@mitmanek: ~$ python repro.py
<?xml version="1.0"?>
<doc><foo/></doc>
Segmentation fault (core dumped)
matej@mitmanek: ~$
This reproduction is done on CentOS7 with libxml2-python-2.9.1-6.el7_2.3.x86_64, python-2.7.5-71.el7.x86_64, and libxml2-2.9.1-6.el7_2.3.x86_64).
More information is in the openSUSE bug#1064286.
In more recent versions of openSUSE (after https://build.opensuse.org/request/show/535476) this crash is masked, but still libxml2-python doesn't handle the error correctly:
matej@milic: ~$ python repro.py
<?xml version="1.0"?>
<doc><foo/></doc>
<?xml version="|�p�U"?>
<`��p�U><���p�U/></`��p�U>
matej@milic: ~$
I would expect some proper error handling, not returning binary junk. Situation with python3 is even more confusing:
matej@milic: ~$ python3 repro.py
<?xml version="1.0"?>
<doc><foo/></doc>
Traceback (most recent call last):
File "repro.py", line 5, in <module>
print(doc)
File "/usr/lib64/python3.6/site-packages/libxml2.py", line 291, in __str__
return self.serialize()
File "/usr/lib64/python3.6/site-packages/libxml2.py", line 408, in serialize
return libxml2mod.serializeNode(self._o, encoding, format)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 15: invalid start byte
matej@milic: ~$
I guess this has nothing to do with Unicode, but all to do again with libxml2-python returning a binary junk.
Expected result: thrown exception about using non-existent variable.