Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
e26fb3ad
Commit
e26fb3ad
authored
May 25, 2017
by
Tom Collins
Committed by
Damien George
May 26, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py/objstringio: Catch mp_uint_t overflow of stream position in write().
parent
ed6d2547
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
6 deletions
+11
-6
py/objstringio.c
py/objstringio.c
+11
-6
No files found.
py/objstringio.c
View file @
e26fb3ad
...
...
@@ -72,22 +72,27 @@ STATIC mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size,
(
void
)
errcode
;
mp_obj_stringio_t
*
o
=
MP_OBJ_TO_PTR
(
o_in
);
check_stringio_is_open
(
o
);
mp_int_t
remaining
=
o
->
vstr
->
alloc
-
o
->
pos
;
mp_uint_t
new_pos
=
o
->
pos
+
size
;
if
(
new_pos
<
size
)
{
// Writing <size> bytes will overflow o->pos beyond limit of mp_uint_t.
*
errcode
=
MP_EFBIG
;
return
MP_STREAM_ERROR
;
}
mp_uint_t
org_len
=
o
->
vstr
->
len
;
if
(
(
mp_int_t
)
size
>
remaining
)
{
if
(
new_pos
>
o
->
vstr
->
alloc
)
{
// Take all what's already allocated...
o
->
vstr
->
len
=
o
->
vstr
->
alloc
;
// ... and add more
vstr_add_len
(
o
->
vstr
,
size
-
remaining
);
vstr_add_len
(
o
->
vstr
,
new_pos
-
o
->
vstr
->
alloc
);
}
// If there was a seek past EOF, clear the hole
if
(
o
->
pos
>
org_len
)
{
memset
(
o
->
vstr
->
buf
+
org_len
,
0
,
o
->
pos
-
org_len
);
}
memcpy
(
o
->
vstr
->
buf
+
o
->
pos
,
buf
,
size
);
o
->
pos
+=
size
;
if
(
o
->
pos
>
o
->
vstr
->
len
)
{
o
->
vstr
->
len
=
o
->
pos
;
o
->
pos
=
new_pos
;
if
(
new_
pos
>
o
->
vstr
->
len
)
{
o
->
vstr
->
len
=
new_
pos
;
}
return
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