Skip to content

Commit a2779e7

Browse files
author
fred.drake
committed
SF bug #1296433 (Expat bug #1515266): Unchecked calls to character data
handler would cause a segfault. This merges in Expat's lib/xmlparse.c revisions 1.154 and 1.155, which fix this and a closely related problem (the later does not affect Python). Moved the crasher test to the tests for xml.parsers.expat. git-svn-id: http://svn.python.org/projects/python/trunk@47191 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 884cc24 commit a2779e7

3 files changed

Lines changed: 23 additions & 56 deletions

File tree

Lib/test/crashers/xml_parsers.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

Lib/test/test_pyexpat.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,24 @@ def check_pos(self, event):
365365
<c/>
366366
</b>
367367
</a>''', 1)
368+
369+
370+
def test_parse_only_xml_data():
371+
# http://python.org/sf/1296433
372+
#
373+
xml = "<?xml version='1.0' encoding='iso8859'?><s>%s</s>" % ('a' * 1025)
374+
# this one doesn't crash
375+
#xml = "<?xml version='1.0'?><s>%s</s>" % ('a' * 10000)
376+
377+
def handler(text):
378+
raise Exception
379+
380+
parser = expat.ParserCreate()
381+
parser.CharacterDataHandler = handler
382+
383+
try:
384+
parser.Parse(xml)
385+
except:
386+
pass
387+
388+
test_parse_only_xml_data()

Modules/expat/xmlparse.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,6 +2552,8 @@ doContent(XML_Parser parser,
25522552
(int)(dataPtr - (ICHAR *)dataBuf));
25532553
if (s == next)
25542554
break;
2555+
if (ps_parsing == XML_FINISHED || ps_parsing == XML_SUSPENDED)
2556+
break;
25552557
*eventPP = s;
25562558
}
25572559
}

0 commit comments

Comments
 (0)