Backport of r74435. Not merged/blocked w/ svnmerge.py as the tool is erroring out...
authorBrett Cannon <bcannon@gmail.com>
Thu, 13 Aug 2009 19:59:04 +0000 (19:59 +0000)
committerBrett Cannon <bcannon@gmail.com>
Thu, 13 Aug 2009 19:59:04 +0000 (19:59 +0000)
Lib/test/test_pyexpat.py
Misc/NEWS
Modules/expat/xmltok_impl.c

index 4947c8b934404aa8e3fe5f01980a6cd7257acdb6..72795be98a36548d256a24ea96d5db93c114fcb6 100644 (file)
@@ -510,6 +510,24 @@ class ChardataBufferTest(unittest.TestCase):
         parser.Parse(xml2, 1)
         self.assertEquals(self.n, 4)
 
+class MalformedInputText(unittest.TestCase):
+    def test1(self):
+        xml = "\0\r\n"
+        parser = expat.ParserCreate()
+        try:
+            parser.Parse(xml, True)
+            self.fail()
+        except expat.ExpatError as e:
+            self.assertEquals(str(e), 'no element found: line 2, column 1')
+
+    def test2(self):
+        xml = "<?xml version\xc2\x85='1.0'?>\r\n"
+        parser = expat.ParserCreate()
+        try:
+            parser.Parse(xml, True)
+            self.fail()
+        except expat.ExpatError as e:
+            self.assertEquals(str(e), 'XML declaration not well-formed: line 1, column 14')
 
 def test_main():
     run_unittest(SetAttributeTest,
@@ -520,7 +538,8 @@ def test_main():
                  HandlerExceptionTest,
                  PositionTest,
                  sf1296433Test,
-                 ChardataBufferTest)
+                 ChardataBufferTest,
+                 MalformedInputText)
 
 if __name__ == "__main__":
     test_main()
index a02bf627749202823c9866f384f24aff21eafdc6..8e56852dbae4e303e2f6b816a4e6cdafd8ecffde 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -105,6 +105,8 @@ syntax error.
 Extension Modules
 -----------------
 
+- Fix a segfault in expat.
+
 - Issue #4509: array.array objects are no longer modified after an operation
   failing due to the resize restriction in-place when the object has exported
   buffers.
index 0ee57abb1f41c720bd374a1884323bb16f42b817..f793a6b8c76fcf09777356ec7cf365eb365fde98 100644 (file)
@@ -1741,7 +1741,7 @@ PREFIX(updatePosition)(const ENCODING *enc,
                        const char *end,
                        POSITION *pos)
 {
-  while (ptr != end) {
+  while (ptr < end) {
     switch (BYTE_TYPE(enc, ptr)) {
 #define LEAD_CASE(n) \
     case BT_LEAD ## n: \