summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_plistlib.py
diff options
context:
space:
mode:
authorNed Deily <nad@acm.org>2011-05-28 09:19:19 (GMT)
committerNed Deily <nad@acm.org>2011-05-28 09:19:19 (GMT)
commitb8e59f77e65ba4caeda8d910bd66df01a468cbea (patch)
treefac7e3f59b617ce67aefd954f0fd67abf099b094 /Lib/test/test_plistlib.py
parent9a7c524dc613595e0d88b3e22b0e49b69467ffc4 (diff)
downloadcpython-b8e59f77e65ba4caeda8d910bd66df01a468cbea.zip
cpython-b8e59f77e65ba4caeda8d910bd66df01a468cbea.tar.gz
cpython-b8e59f77e65ba4caeda8d910bd66df01a468cbea.tar.bz2
Issue #985064: Make plistlib more resilient to faulty input plists.
Patch by Mher Movsisyan.
Diffstat (limited to 'Lib/test/test_plistlib.py')
-rw-r--r--Lib/test/test_plistlib.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py
index b9a46b7..ccda920 100644
--- a/Lib/test/test_plistlib.py
+++ b/Lib/test/test_plistlib.py
@@ -175,6 +175,32 @@ class TestPlistlib(unittest.TestCase):
self.assertEqual(test1, result1)
self.assertEqual(test2, result2)
+ def test_invalidarray(self):
+ for i in ["<key>key inside an array</key>",
+ "<key>key inside an array2</key><real>3</real>",
+ "<true/><key>key inside an array3</key>"]:
+ self.assertRaises(ValueError, plistlib.readPlistFromBytes,
+ ("<plist><array>%s</array></plist>"%i).encode())
+
+ def test_invaliddict(self):
+ for i in ["<key><true/>k</key><string>compound key</string>",
+ "<key>single key</key>",
+ "<string>missing key</string>",
+ "<key>k1</key><string>v1</string><real>5.3</real>"
+ "<key>k1</key><key>k2</key><string>double key</string>"]:
+ self.assertRaises(ValueError, plistlib.readPlistFromBytes,
+ ("<plist><dict>%s</dict></plist>"%i).encode())
+ self.assertRaises(ValueError, plistlib.readPlistFromBytes,
+ ("<plist><array><dict>%s</dict></array></plist>"%i).encode())
+
+ def test_invalidinteger(self):
+ self.assertRaises(ValueError, plistlib.readPlistFromBytes,
+ b"<plist><integer>not integer</integer></plist>")
+
+ def test_invalidreal(self):
+ self.assertRaises(ValueError, plistlib.readPlistFromBytes,
+ b"<plist><integer>not real</integer></plist>")
+
def test_main():
support.run_unittest(TestPlistlib)