diff options
author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2009-02-28 11:39:45 (GMT) |
---|---|---|
committer | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2009-02-28 11:39:45 (GMT) |
commit | e363fa020b1775879f16bac99e2eb5f1d42f8fd3 (patch) | |
tree | 04c4e02e0a7ea14ccd87253e5b2dbc0f47d21fa5 /Lib/test | |
parent | bebfd256ee039c21e895dd6d496b4ea0416a5c83 (diff) | |
download | cpython-e363fa020b1775879f16bac99e2eb5f1d42f8fd3.zip cpython-e363fa020b1775879f16bac99e2eb5f1d42f8fd3.tar.gz cpython-e363fa020b1775879f16bac99e2eb5f1d42f8fd3.tar.bz2 |
Merged revisions 70052 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70052 | hirokazu.yamamoto | 2009-02-28 19:31:54 +0900 | 2 lines
Issue #5386: mmap.write_byte didn't check map size, so it could cause buffer
overrun.
........
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_mmap.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index c06b757..c8e52a6 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -467,6 +467,38 @@ class MmapTests(unittest.TestCase): self.assert_(issubclass(mmap.error, EnvironmentError)) self.assert_("mmap.error" in str(mmap.error)) + def test_io_methods(self): + data = "0123456789" + open(TESTFN, "wb").write("x"*len(data)) + f = open(TESTFN, "r+b") + m = mmap.mmap(f.fileno(), len(data)) + f.close() + # Test write_byte() + for i in xrange(len(data)): + self.assertEquals(m.tell(), i) + m.write_byte(data[i:i+1]) + self.assertEquals(m.tell(), i+1) + self.assertRaises(ValueError, m.write_byte, "x") + self.assertEquals(m[:], data) + # Test read_byte() + m.seek(0) + for i in xrange(len(data)): + self.assertEquals(m.tell(), i) + self.assertEquals(m.read_byte(), data[i:i+1]) + self.assertEquals(m.tell(), i+1) + self.assertRaises(ValueError, m.read_byte) + # Test read() + m.seek(3) + self.assertEquals(m.read(3), "345") + self.assertEquals(m.tell(), 6) + # Test write() + m.seek(3) + m.write("bar") + self.assertEquals(m.tell(), 6) + self.assertEquals(m[:], "012bar6789") + m.seek(8) + self.assertRaises(ValueError, m.write, "bar") + def test_main(): run_unittest(MmapTests) |