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
1bfe9dc8
Commit
1bfe9dc8
authored
May 07, 2008
by
Alexandre Vassalotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed _bytesio.c to avoid comparing a signed with an unsigned value.
Added tests for overflow checks.
parent
2e0419dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
10 deletions
+16
-10
Lib/test/test_memoryio.py
Lib/test/test_memoryio.py
+14
-0
Modules/_bytesio.c
Modules/_bytesio.c
+2
-10
No files found.
Lib/test/test_memoryio.py
View file @
1bfe9dc8
...
...
@@ -7,6 +7,7 @@ import unittest
from
test
import
test_support
import
io
import
sys
try
:
import
_bytesio
...
...
@@ -403,6 +404,19 @@ if has_c_implementation:
class
CBytesIOTest
(
PyBytesIOTest
):
ioclass
=
io
.
BytesIO
def
test_overflow
(
self
):
buf
=
self
.
buftype
(
"a"
)
memio
=
self
.
ioclass
()
memio
.
seek
(
sys
.
maxsize
)
self
.
assertRaises
(
OverflowError
,
memio
.
seek
,
1
,
1
)
# Ensure that the position has not been changed
self
.
assertEqual
(
memio
.
tell
(),
sys
.
maxsize
)
self
.
assertEqual
(
memio
.
write
(
self
.
EOF
),
0
)
self
.
assertRaises
(
OverflowError
,
memio
.
write
,
buf
)
self
.
assertEqual
(
memio
.
tell
(),
sys
.
maxsize
)
def
test_main
():
tests
=
[
PyBytesIOTest
,
PyStringIOTest
]
if
has_c_implementation
:
...
...
Modules/_bytesio.c
View file @
1bfe9dc8
...
...
@@ -110,16 +110,8 @@ write_bytes(BytesIOObject *self, const char *bytes, Py_ssize_t len)
assert
(
self
->
pos
>=
0
);
assert
(
len
>=
0
);
/* This overflow check is not strictly necessary. However, it avoids us to
deal with funky things like comparing an unsigned and a signed
integer. */
if
(
self
->
pos
>
PY_SSIZE_T_MAX
-
len
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"new position too large"
);
return
-
1
;
}
if
(
self
->
pos
+
len
>
self
->
buf_size
)
{
if
(
resize_buffer
(
self
,
self
->
pos
+
len
)
<
0
)
if
((
size_t
)
self
->
pos
+
len
>
self
->
buf_size
)
{
if
(
resize_buffer
(
self
,
(
size_t
)
self
->
pos
+
len
)
<
0
)
return
-
1
;
}
...
...
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