Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
941bfcc5
Commit
941bfcc5
authored
Sep 10, 2012
by
Jesus Cea
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes #15676: mmap: add empty file check prior to offset check
parent
7330da42
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
0 deletions
+17
-0
Lib/test/test_mmap.py
Lib/test/test_mmap.py
+9
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/mmapmodule.c
Modules/mmapmodule.c
+5
-0
No files found.
Lib/test/test_mmap.py
View file @
941bfcc5
...
...
@@ -459,6 +459,15 @@ class MmapTests(unittest.TestCase):
f
.
flush
()
return
mmap
.
mmap
(
f
.
fileno
(),
0
)
def
test_empty_file
(
self
):
f
=
open
(
TESTFN
,
'w+b'
)
f
.
close
()
f
=
open
(
TESTFN
,
"rb"
)
self
.
assertRaisesRegex
(
ValueError
,
"cannot mmap an empty file"
,
mmap
.
mmap
,
f
.
fileno
(),
0
,
access
=
mmap
.
ACCESS_READ
)
f
.
close
()
def
test_offset
(
self
):
f
=
open
(
TESTFN
,
'w+b'
)
...
...
Misc/NEWS
View file @
941bfcc5
...
...
@@ -463,6 +463,9 @@ Library
Extension Modules
-----------------
- Issue #15676: Now "mmap" check for empty files before doing the
offset check. Patch by Steven Willis.
- Issue #6493: An issue in ctypes on Windows that caused structure bitfields
of type ctypes.c_uint32 and width 32 to incorrectly be set has been fixed.
...
...
Modules/mmapmodule.c
View file @
941bfcc5
...
...
@@ -1141,6 +1141,11 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
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"
);
return
NULL
;
}
if
(
offset
>=
st
.
st_size
)
{
PyErr_SetString
(
PyExc_ValueError
,
"mmap offset is greater than file size"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment