~ubuntu-branches/ubuntu/raring/python3.3/raring-proposed

« back to all changes in this revision

Viewing changes to Modules/mmapmodule.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-03-26 12:13:24 UTC
  • mfrom: (22.1.5 experimental)
  • Revision ID: package-import@ubuntu.com-20130326121324-th46djl07tq5hjwb
Tags: 3.3.1~rc1-1ubuntu1
* Merge with Debian; remaining changes:
  - Build-depend on python3:any instead of python3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1162
1162
#  endif
1163
1163
    if (fd != -1 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
1164
1164
        if (map_size == 0) {
1165
 
            off_t calc_size;
 
1165
            if (st.st_size == 0) {
 
1166
                PyErr_SetString(PyExc_ValueError,
 
1167
                                "cannot mmap an empty file");
 
1168
                return NULL;
 
1169
            }
1166
1170
            if (offset >= st.st_size) {
1167
1171
                PyErr_SetString(PyExc_ValueError,
1168
1172
                                "mmap offset is greater than file size");
1169
1173
                return NULL;
1170
1174
            }
1171
 
            calc_size = st.st_size - offset;
1172
 
            map_size = calc_size;
1173
 
            if (map_size != calc_size) {
 
1175
            if (st.st_size - offset > PY_SSIZE_T_MAX) {
1174
1176
                PyErr_SetString(PyExc_ValueError,
1175
1177
                                 "mmap length is too large");
1176
 
                 return NULL;
1177
 
             }
 
1178
                return NULL;
 
1179
            }
 
1180
            map_size = (Py_ssize_t) (st.st_size - offset);
1178
1181
        } else if (offset + (size_t)map_size > st.st_size) {
1179
1182
            PyErr_SetString(PyExc_ValueError,
1180
1183
                            "mmap length is greater than file size");
1359
1362
            }
1360
1363
 
1361
1364
            size = (((PY_LONG_LONG) high) << 32) + low;
 
1365
            if (size == 0) {
 
1366
                PyErr_SetString(PyExc_ValueError,
 
1367
                                "cannot mmap an empty file");
 
1368
                Py_DECREF(m_obj);
 
1369
                return NULL;
 
1370
            }
1362
1371
            if (offset >= size) {
1363
1372
                PyErr_SetString(PyExc_ValueError,
1364
1373
                                "mmap offset is greater than file size");
1365
1374
                Py_DECREF(m_obj);
1366
1375
                return NULL;
1367
1376
            }
1368
 
            if (offset - size > PY_SSIZE_T_MAX)
1369
 
                /* Map area too large to fit in memory */
1370
 
                m_obj->size = (Py_ssize_t) -1;
1371
 
            else
1372
 
                m_obj->size = (Py_ssize_t) (size - offset);
 
1377
            if (size - offset > PY_SSIZE_T_MAX) {
 
1378
                PyErr_SetString(PyExc_ValueError,
 
1379
                                "mmap length is too large");
 
1380
                Py_DECREF(m_obj);
 
1381
                return NULL;
 
1382
            }
 
1383
            m_obj->size = (Py_ssize_t) (size - offset);
1373
1384
        } else {
1374
1385
            m_obj->size = map_size;
1375
1386
            size = offset + map_size;