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
736b8012
Commit
736b8012
authored
Sep 29, 2014
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent overflow in unicode_repr (closes #22520)
parent
bbd0a323
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
11 deletions
+20
-11
Misc/NEWS
Misc/NEWS
+3
-0
Objects/unicodeobject.c
Objects/unicodeobject.c
+17
-11
No files found.
Misc/NEWS
View file @
736b8012
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.3.6 release candidate 1?
Core and Builtins
-----------------
- Issue #22520: Fix overflow checking when generating the repr of a unicode
object.
- Issue #22519: Fix overflow checking in PyBytes_Repr.
- Issue #22518: Fix integer overflow issues in latin-1 encoding.
...
...
Objects/unicodeobject.c
View file @
736b8012
...
...
@@ -12000,28 +12000,34 @@ unicode_repr(PyObject *unicode)
ikind
=
PyUnicode_KIND
(
unicode
);
for
(
i
=
0
;
i
<
isize
;
i
++
)
{
Py_UCS4
ch
=
PyUnicode_READ
(
ikind
,
idata
,
i
);
Py_ssize_t
incr
=
1
;
switch
(
ch
)
{
case
'\''
:
squote
++
;
osize
++
;
break
;
case
'"'
:
dquote
++
;
osize
++
;
break
;
case
'\''
:
squote
++
;
break
;
case
'"'
:
dquote
++
;
break
;
case
'\\'
:
case
'\t'
:
case
'\r'
:
case
'\n'
:
osize
+=
2
;
break
;
incr
=
2
;
break
;
default:
/* Fast-path ASCII */
if
(
ch
<
' '
||
ch
==
0x7f
)
osize
+
=
4
;
/* \xHH */
incr
=
4
;
/* \xHH */
else
if
(
ch
<
0x7f
)
osize
++
;
else
if
(
Py_UNICODE_ISPRINTABLE
(
ch
))
{
osize
++
;
;
else
if
(
Py_UNICODE_ISPRINTABLE
(
ch
))
max
=
ch
>
max
?
ch
:
max
;
}
else
if
(
ch
<
0x100
)
osize
+
=
4
;
/* \xHH */
incr
=
4
;
/* \xHH */
else
if
(
ch
<
0x10000
)
osize
+
=
6
;
/* \uHHHH */
incr
=
6
;
/* \uHHHH */
else
osize
+=
10
;
/* \uHHHHHHHH */
incr
=
10
;
/* \uHHHHHHHH */
}
if
(
osize
>
PY_SSIZE_T_MAX
-
incr
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"string is too long to generate repr"
);
return
NULL
;
}
osize
+=
incr
;
}
quote
=
'\''
;
...
...
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