Skip to content

Commit 5dd40e5

Browse files
committed
Issue #19815: Fix segfault when parsing empty namespace declaration.
Based on patches by Christian Heimes and Vajrasky Kok
1 parent c303cfd commit 5dd40e5

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

Lib/test/test_xml_etree.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ def test_iterparse(self):
535535
('end-ns', None),
536536
])
537537

538+
events = ('start-ns', 'end-ns')
539+
context = iterparse(io.StringIO(r"<root xmlns=''/>"), events)
540+
res = [action for action, elem in context]
541+
self.assertEqual(res, ['start-ns', 'end-ns'])
542+
538543
events = ("start", "end", "bogus")
539544
with self.assertRaises(ValueError) as cm:
540545
with open(SIMPLE_XMLFILE, "rb") as f:

Modules/_elementtree.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2997,7 +2997,10 @@ expat_start_ns_handler(XMLParserObject* self, const XML_Char* prefix,
29972997
PyObject* sprefix = NULL;
29982998
PyObject* suri = NULL;
29992999

3000-
suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict");
3000+
if (uri)
3001+
suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict");
3002+
else
3003+
suri = PyUnicode_FromString("");
30013004
if (!suri)
30023005
return;
30033006

0 commit comments

Comments
 (0)