[Python-checkins] r69736 - in python/branches/py3k: Lib/test/test_mmap.py Misc/NEWS Modules/mmapmodule.c
hirokazu.yamamoto
python-checkins at python.org
Wed Feb 18 17:38:00 CET 2009
Author: hirokazu.yamamoto
Date: Wed Feb 18 17:38:00 2009
New Revision: 69736
Log:
Merged revisions 69714,69718 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r69714 | hirokazu.yamamoto | 2009-02-17 19:12:10 +0900 | 1 line
Issue #5292: Fixed mmap crash on its boundary access m[len(m)].
........
r69718 | hirokazu.yamamoto | 2009-02-17 22:17:26 +0900 | 3 lines
Issue #5282: Fixed mmap resize on 32bit windows and unix. When offset > 0,
The file was resized to wrong size.
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Lib/test/test_mmap.py
python/branches/py3k/Misc/NEWS
python/branches/py3k/Modules/mmapmodule.c
Modified: python/branches/py3k/Lib/test/test_mmap.py
==============================================================================
--- python/branches/py3k/Lib/test/test_mmap.py (original)
+++ python/branches/py3k/Lib/test/test_mmap.py Wed Feb 18 17:38:00 2009
@@ -42,6 +42,10 @@
self.assertEqual(m[0], 0)
self.assertEqual(m[0:3], b'\0\0\0')
+ # Shouldn't crash on boundary (Issue #5292)
+ self.assertRaises(IndexError, m.__getitem__, len(m))
+ self.assertRaises(IndexError, m.__setitem__, len(m), b'\0')
+
# Modify the file's content
m[0] = b'3'[0]
m[PAGESIZE +3: PAGESIZE +3+3] = b'bar'
@@ -412,6 +416,27 @@
m = mmap.mmap(f.fileno(), mapsize - halfsize, offset=halfsize)
self.assertEqual(m[0:3], b'foo')
f.close()
+
+ # Try resizing map
+ try:
+ m.resize(512)
+ except SystemError:
+ pass
+ else:
+ # resize() is supported
+ self.assertEqual(len(m), 512)
+ # Check that we can no longer seek beyond the new size.
+ self.assertRaises(ValueError, m.seek, 513, 0)
+ # Check that the content is not changed
+ self.assertEqual(m[0:3], b'foo')
+
+ # Check that the underlying file is truncated too
+ f = open(TESTFN)
+ f.seek(0, 2)
+ self.assertEqual(f.tell(), halfsize + 512)
+ f.close()
+ self.assertEqual(m.size(), halfsize + 512)
+
m.close()
finally:
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Wed Feb 18 17:38:00 2009
@@ -169,6 +169,11 @@
Library
-------
+- Issue #5282: Fixed mmap resize on 32bit windows and unix. When offset > 0,
+ The file was resized to wrong size.
+
+- Issue #5292: Fixed mmap crash on its boundary access m[len(m)].
+
- Issue #2279: distutils.sdist.add_defaults now add files
from the package_data and the data_files metadata.
Modified: python/branches/py3k/Modules/mmapmodule.c
==============================================================================
--- python/branches/py3k/Modules/mmapmodule.c (original)
+++ python/branches/py3k/Modules/mmapmodule.c Wed Feb 18 17:38:00 2009
@@ -455,7 +455,7 @@
off_lo = (DWORD)(self->offset & 0xFFFFFFFF);
#else
newSizeHigh = 0;
- newSizeLow = (DWORD)new_size;
+ newSizeLow = (DWORD)(self->offset + new_size);
off_hi = 0;
off_lo = (DWORD)self->offset;
#endif
@@ -501,7 +501,7 @@
} else {
void *newmap;
- if (ftruncate(self->fd, new_size) == -1) {
+ if (ftruncate(self->fd, self->offset + new_size) == -1) {
PyErr_SetFromErrno(mmap_module_error);
return NULL;
}
@@ -692,7 +692,7 @@
return NULL;
if (i < 0)
i += self->size;
- if (i < 0 || (size_t)i > self->size) {
+ if (i < 0 || (size_t)i >= self->size) {
PyErr_SetString(PyExc_IndexError,
"mmap index out of range");
return NULL;
@@ -797,7 +797,7 @@
return -1;
if (i < 0)
i += self->size;
- if (i < 0 || (size_t)i > self->size) {
+ if (i < 0 || (size_t)i >= self->size) {
PyErr_SetString(PyExc_IndexError,
"mmap index out of range");
return -1;
More information about the Python-checkins
mailing list