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
64e461be
Commit
64e461be
authored
Jul 11, 2017
by
Serhiy Storchaka
Committed by
GitHub
Jul 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-22207: Add checks for possible integer overflows in unicodeobject.c. (#2623)
Based on patch by Victor Stinner.
parent
1180e5a5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
6 deletions
+12
-6
Objects/unicodeobject.c
Objects/unicodeobject.c
+12
-6
No files found.
Objects/unicodeobject.c
View file @
64e461be
...
...
@@ -5478,13 +5478,12 @@ _PyUnicode_EncodeUTF32(PyObject *str,
/* four bytes are reserved for each surrogate */
if
(
moreunits
>
1
)
{
Py_ssize_t
outpos
=
out
-
(
uint32_t
*
)
PyBytes_AS_STRING
(
v
);
Py_ssize_t
morebytes
=
4
*
(
moreunits
-
1
);
if
(
PyBytes_GET_SIZE
(
v
)
>
PY_SSIZE_T_MAX
-
morebytes
)
{
if
(
moreunits
>=
(
PY_SSIZE_T_MAX
-
PyBytes_GET_SIZE
(
v
))
/
4
)
{
/* integer overflow */
PyErr_NoMemory
();
goto
error
;
}
if
(
_PyBytes_Resize
(
&
v
,
PyBytes_GET_SIZE
(
v
)
+
morebytes
)
<
0
)
if
(
_PyBytes_Resize
(
&
v
,
PyBytes_GET_SIZE
(
v
)
+
4
*
(
moreunits
-
1
)
)
<
0
)
goto
error
;
out
=
(
uint32_t
*
)
PyBytes_AS_STRING
(
v
)
+
outpos
;
}
...
...
@@ -5830,13 +5829,12 @@ _PyUnicode_EncodeUTF16(PyObject *str,
/* two bytes are reserved for each surrogate */
if
(
moreunits
>
1
)
{
Py_ssize_t
outpos
=
out
-
(
unsigned
short
*
)
PyBytes_AS_STRING
(
v
);
Py_ssize_t
morebytes
=
2
*
(
moreunits
-
1
);
if
(
PyBytes_GET_SIZE
(
v
)
>
PY_SSIZE_T_MAX
-
morebytes
)
{
if
(
moreunits
>=
(
PY_SSIZE_T_MAX
-
PyBytes_GET_SIZE
(
v
))
/
2
)
{
/* integer overflow */
PyErr_NoMemory
();
goto
error
;
}
if
(
_PyBytes_Resize
(
&
v
,
PyBytes_GET_SIZE
(
v
)
+
morebytes
)
<
0
)
if
(
_PyBytes_Resize
(
&
v
,
PyBytes_GET_SIZE
(
v
)
+
2
*
(
moreunits
-
1
)
)
<
0
)
goto
error
;
out
=
(
unsigned
short
*
)
PyBytes_AS_STRING
(
v
)
+
outpos
;
}
...
...
@@ -6516,6 +6514,10 @@ _PyUnicode_DecodeUnicodeInternal(const char *s,
1
))
return
NULL
;
if
(
size
<
0
)
{
PyErr_BadInternalCall
();
return
NULL
;
}
if
(
size
==
0
)
_Py_RETURN_UNICODE_EMPTY
();
...
...
@@ -7303,6 +7305,10 @@ decode_code_page_stateful(int code_page,
PyErr_SetString
(
PyExc_ValueError
,
"invalid code page number"
);
return
NULL
;
}
if
(
size
<
0
)
{
PyErr_BadInternalCall
();
return
NULL
;
}
if
(
consumed
)
*
consumed
=
0
;
...
...
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