Repository navigation
Closed
Description
When
import xmlsec
is added to trivial python code which uses lxml's etree.parse, the second etree.parse fails.
Let's have minimal XML file sf.xml containing
<data/>
Let's have trivial code sf.py
from lxml import etree
# import xmlsec
xml1 = etree.parse("sf.xml")
print(xml1)
xml2 = etree.parse("sf.xml")
print(xml2)
Running it with python3 sf.py produces two objects:
<lxml.etree._ElementTree object at 0x7fe067e3ae88>
<lxml.etree._ElementTree object at 0x7fe067e3adc8>
However, when that import xmlsec is uncommented, the behaviour changes to
<lxml.etree._ElementTree object at 0x7fe8e2419548>
Traceback (most recent call last):
File "sf.py", line 5, in <module>
xml2 = etree.parse("sf.xml")
File "src/lxml/etree.pyx", line 3426, in lxml.etree.parse
File "src/lxml/parser.pxi", line 1840, in lxml.etree._parseDocument
File "src/lxml/parser.pxi", line 1866, in lxml.etree._parseDocumentFromURL
File "src/lxml/parser.pxi", line 1770, in lxml.etree._parseDocFromFile
File "src/lxml/parser.pxi", line 1163, in lxml.etree._BaseParser._parseDocFromFile
File "src/lxml/parser.pxi", line 601, in lxml.etree._ParserContext._handleParseResultDoc
File "src/lxml/parser.pxi", line 711, in lxml.etree._handleParseResult
File "src/lxml/parser.pxi", line 651, in lxml.etree._raiseParseError
This is with xmlsec that was installed via pip3 on Fedora 28:
# pip3 install xmlsec
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting xmlsec
Using cached https://files.pythonhosted.org/packages/35/42/d7cd323c91d4706f3cc32ffe7d5f851ab8ef9898ccb350f6ba593dd8b89a/xmlsec-1.3.3.tar.gz
Requirement already satisfied: pkgconfig in /usr/local/lib/python3.6/site-packages (from xmlsec)
Requirement already satisfied: lxml>=3.0 in /usr/lib64/python3.6/site-packages (from xmlsec)
Installing collected packages: xmlsec
Running setup.py install for xmlsec ... done
Successfully installed xmlsec-1.3.3
This is upstream version of Fedora bug https://bugzilla.redhat.com/show_bug.cgi?id=1665459. With xmlsec installed via pip3 I don't get that segfault ... but note that the traceback ends with empty line, where some error message ("cannot parse file") would be expected.
Metadata
Metadata
Assignees
Labels
No labels
Activity
baynes commentedon Mar 24, 2020
I have seen the same on Centos 7. It forced us to use pyxmlsec instead of python-xmlsec which forces us to stick with Python2!
It is worth noting that with pyxmlsec, if olxml eltree can also give problems in some cases. Though that seems to be linked to when an error hanlder is invoked and cases python to segfault. It might be a separate problem in pyxmlsec or it might an indication of an underlying probem in lxml , libxmlsec or libxml2.
hoefling commentedon May 21, 2020
I can't reproduce this issue with the latest 1.3.8 anymore:
Ping me if this issue should be reopened though!
hoefling commentedon May 22, 2020
Nope, not resolved - I've tested with the
lxmlfrom PyPI, not CentOS package. Looks like it's the same issue as #84 for Arch.hoefling commentedon May 22, 2020
It looks like an
lxmlissue to me - check the reasoning here. The workaround is to reset the default XML parser object after eachetree.parse()invocation:or pass a new parser instance explicitly:
hoefling commentedon May 22, 2020
For reference: https://bugs.launchpad.net/lxml/+bug/1880251
[-]importing xmlsec breaks secondl xml.etree.parse call[/-][+]importing xmlsec breaks second lxml.etree.parse call[/+]stanislavlevin commentedon Mar 28, 2022
self-tests of
python-xmlsecwithPYXMLSEC_TEST_ITERATIONS> 0 fail due to this issue:used versions:
though the workaround you proposed works:
xmlsec workaround for gh#xmlsec#84
xmlsec workaround for gh#xmlsec#84