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
ad62b039
Commit
ad62b039
authored
Jan 18, 2011
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10451: memoryview objects could allow to mutate a readable buffer.
Initial patch by Ross Lagerwall.
parent
c8a16867
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
4 deletions
+18
-4
Lib/test/test_getargs2.py
Lib/test/test_getargs2.py
+3
-1
Lib/test/test_memoryview.py
Lib/test/test_memoryview.py
+12
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/memoryobject.c
Objects/memoryobject.c
+0
-3
No files found.
Lib/test/test_getargs2.py
View file @
ad62b039
...
...
@@ -381,8 +381,10 @@ class Bytes_TestCase(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
getargs_w_star
,
'abc
\
xe9
'
)
self
.
assertRaises
(
TypeError
,
getargs_w_star
,
b'bytes'
)
self
.
assertRaises
(
TypeError
,
getargs_w_star
,
b'nul:
\
0
'
)
self
.
assertRaises
(
TypeError
,
getargs_w_star
,
memoryview
(
b'bytes'
))
self
.
assertEqual
(
getargs_w_star
(
bytearray
(
b'bytearray'
)),
b'[ytearra]'
)
self
.
assertEqual
(
getargs_w_star
(
memoryview
(
b'memoryview'
)),
b'[emoryvie]'
)
self
.
assertEqual
(
getargs_w_star
(
memoryview
(
bytearray
(
b'memoryview'
))),
b'[emoryvie]'
)
self
.
assertRaises
(
TypeError
,
getargs_w_star
,
None
)
...
...
Lib/test/test_memoryview.py
View file @
ad62b039
...
...
@@ -9,6 +9,7 @@ import sys
import
gc
import
weakref
import
array
import
io
class
AbstractMemoryTests
:
...
...
@@ -271,6 +272,17 @@ class AbstractMemoryTests:
m
.
release
()
self
.
_check_released
(
m
,
tp
)
def
test_writable_readonly
(
self
):
# Issue #10451: memoryview incorrectly exposes a readonly
# buffer as writable causing a segfault if using mmap
tp
=
self
.
ro_type
if
tp
is
None
:
return
b
=
tp
(
self
.
_source
)
m
=
self
.
_view
(
b
)
i
=
io
.
BytesIO
(
b'ZZZZ'
)
self
.
assertRaises
(
TypeError
,
i
.
readinto
,
m
)
# Variations on source objects for the buffer: bytes-like objects, then arrays
# with itemsize > 1.
# NOTE: support for multi-dimensional objects is unimplemented.
...
...
Misc/NEWS
View file @
ad62b039
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.2 Release Candidate 2?
Core and Builtins
-----------------
- Issue #10451: memoryview objects could allow to mutate a readable buffer.
Initial patch by Ross Lagerwall.
Library
-------
...
...
Objects/memoryobject.c
View file @
ad62b039
...
...
@@ -52,9 +52,6 @@ memory_getbuf(PyMemoryViewObject *self, Py_buffer *view, int flags)
{
int
res
=
0
;
CHECK_RELEASED_INT
(
self
);
/* XXX for whatever reason fixing the flags seems necessary */
if
(
self
->
view
.
readonly
)
flags
&=
~
PyBUF_WRITABLE
;
if
(
self
->
view
.
obj
!=
NULL
)
res
=
PyObject_GetBuffer
(
self
->
view
.
obj
,
view
,
flags
);
if
(
view
)
...
...
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