Mailing List Archive

python/dist/src/Lib/test test_mmap.py,1.19.8.2,1.19.8.3
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv12162/Lib/test

Modified Files:
Tag: release22-maint
test_mmap.py
Log Message:
Backport of SF bug # 585792, Invalid mmap crashes Python interpreter

Raise ValueError if user passes a size to mmap which is larger
than the file.

Also need Tim's fix in test_mmap.py, 1.22 which flushes the file
before mmap'ing it.



Index: test_mmap.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_mmap.py,v
retrieving revision 1.19.8.2
retrieving revision 1.19.8.3
diff -C2 -d -r1.19.8.2 -r1.19.8.3
*** test_mmap.py 23 Aug 2002 15:50:57 -0000 1.19.8.2
--- test_mmap.py 5 Sep 2002 22:30:03 -0000 1.19.8.3
***************
*** 18,21 ****
--- 18,22 ----
f.write('foo')
f.write('\0'* (PAGESIZE-3) )
+ f.flush()

m = mmap.mmap(f.fileno(), 2 * PAGESIZE)
***************
*** 189,192 ****
--- 190,208 ----
verify(open(TESTFN, "rb").read() == 'a'*mapsize,
"Readonly memory map data file was modified")
+
+ print " Opening mmap with size too big"
+ import sys
+ f = open(TESTFN, "r+b")
+ try:
+ m = mmap.mmap(f.fileno(), mapsize+1)
+ except ValueError:
+ # we do not expect a ValueError on Windows
+ if sys.platform.startswith('win'):
+ verify(0, "Opening mmap with size+1 should work on Windows.")
+ pass
+ else:
+ # we expect a ValueError on Unix, but not on Windows
+ if not sys.platform.startswith('win'):
+ verify(0, "Opening mmap with size+1 should raise ValueError.")

print " Opening mmap with access=ACCESS_WRITE"