summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRichard Oudkerk <shibturn@gmail.com>2013-02-13 12:33:53 (GMT)
committerRichard Oudkerk <shibturn@gmail.com>2013-02-13 12:33:53 (GMT)
commit76450e6a84fe25db47326ef865ca9ea3968d319f (patch)
tree5eda20648c8957a1b5c53acfe1d1493c4a036aad /Modules
parent082022b68308cc45639b450ce0c55f183a784b67 (diff)
parent6d40134eba5633e93a4c45d0d2868b9f1a02439a (diff)
downloadcpython-76450e6a84fe25db47326ef865ca9ea3968d319f.zip
cpython-76450e6a84fe25db47326ef865ca9ea3968d319f.tar.gz
cpython-76450e6a84fe25db47326ef865ca9ea3968d319f.tar.bz2
Merge
Diffstat (limited to 'Modules')
-rw-r--r--Modules/mmapmodule.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index d650eae..1107eb8 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -1162,7 +1162,6 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
# endif
if (fd != -1 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
if (map_size == 0) {
- off_t calc_size;
if (st.st_size == 0) {
PyErr_SetString(PyExc_ValueError,
"cannot mmap an empty file");
@@ -1173,13 +1172,12 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
"mmap offset is greater than file size");
return NULL;
}
- calc_size = st.st_size - offset;
- map_size = calc_size;
- if (map_size != calc_size) {
+ if (st.st_size - offset > PY_SSIZE_T_MAX) {
PyErr_SetString(PyExc_ValueError,
"mmap length is too large");
- return NULL;
- }
+ return NULL;
+ }
+ map_size = (Py_ssize_t) (st.st_size - offset);
} else if (offset + (size_t)map_size > st.st_size) {
PyErr_SetString(PyExc_ValueError,
"mmap length is greater than file size");
@@ -1376,11 +1374,13 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
Py_DECREF(m_obj);
return NULL;
}
- if (offset - size > PY_SSIZE_T_MAX)
- /* Map area too large to fit in memory */
- m_obj->size = (Py_ssize_t) -1;
- else
- m_obj->size = (Py_ssize_t) (size - offset);
+ if (size - offset > PY_SSIZE_T_MAX) {
+ PyErr_SetString(PyExc_ValueError,
+ "mmap length is too large");
+ Py_DECREF(m_obj);
+ return NULL;
+ }
+ m_obj->size = (Py_ssize_t) (size - offset);
} else {
m_obj->size = map_size;
size = offset + map_size;