Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c81107

Browse files
committed
Backport of r74435. Not merged/blocked w/ svnmerge.py as the tool is erroring out on me.
1 parent 790da23 commit 0c81107

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

Lib/test/test_pyexpat.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,24 @@ def test_change_size_2(self):
510510
parser.Parse(xml2, 1)
511511
self.assertEquals(self.n, 4)
512512

513+
class MalformedInputText(unittest.TestCase):
514+
def test1(self):
515+
xml = "\0\r\n"
516+
parser = expat.ParserCreate()
517+
try:
518+
parser.Parse(xml, True)
519+
self.fail()
520+
except expat.ExpatError as e:
521+
self.assertEquals(str(e), 'no element found: line 2, column 1')
522+
523+
def test2(self):
524+
xml = "<?xml version\xc2\x85='1.0'?>\r\n"
525+
parser = expat.ParserCreate()
526+
try:
527+
parser.Parse(xml, True)
528+
self.fail()
529+
except expat.ExpatError as e:
530+
self.assertEquals(str(e), 'XML declaration not well-formed: line 1, column 14')
513531

514532
def test_main():
515533
run_unittest(SetAttributeTest,
@@ -520,7 +538,8 @@ def test_main():
520538
HandlerExceptionTest,
521539
PositionTest,
522540
sf1296433Test,
523-
ChardataBufferTest)
541+
ChardataBufferTest,
542+
MalformedInputText)
524543

525544
if __name__ == "__main__":
526545
test_main()

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ syntax error.
105105
Extension Modules
106106
-----------------
107107

108+
- Fix a segfault in expat.
109+
108110
- Issue #4509: array.array objects are no longer modified after an operation
109111
failing due to the resize restriction in-place when the object has exported
110112
buffers.

Modules/expat/xmltok_impl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ PREFIX(updatePosition)(const ENCODING *enc,
17411741
const char *end,
17421742
POSITION *pos)
17431743
{
1744-
while (ptr != end) {
1744+
while (ptr < end) {
17451745
switch (BYTE_TYPE(enc, ptr)) {
17461746
#define LEAD_CASE(n) \
17471747
case BT_LEAD ## n: \

0 commit comments

Comments
 (0)