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
42ff1055
Commit
42ff1055
authored
Sep 29, 2014
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix overflow checking in PyBytes_Repr (closes #22519)
parent
3bbb2e48
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
12 deletions
+18
-12
Misc/NEWS
Misc/NEWS
+2
-0
Objects/bytesobject.c
Objects/bytesobject.c
+16
-12
No files found.
Misc/NEWS
View file @
42ff1055
...
@@ -10,6 +10,8 @@ What's New in Python 3.3.6 release candidate 1?
...
@@ -10,6 +10,8 @@ What's New in Python 3.3.6 release candidate 1?
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #22519: Fix overflow checking in PyBytes_Repr.
- Issue #22518: Fix integer overflow issues in latin-1 encoding.
- Issue #22518: Fix integer overflow issues in latin-1 encoding.
Library
Library
...
...
Objects/bytesobject.c
View file @
42ff1055
...
@@ -593,28 +593,27 @@ PyBytes_Repr(PyObject *obj, int smartquotes)
...
@@ -593,28 +593,27 @@ PyBytes_Repr(PyObject *obj, int smartquotes)
newsize
=
3
;
/* b'' */
newsize
=
3
;
/* b'' */
s
=
(
unsigned
char
*
)
op
->
ob_sval
;
s
=
(
unsigned
char
*
)
op
->
ob_sval
;
for
(
i
=
0
;
i
<
length
;
i
++
)
{
for
(
i
=
0
;
i
<
length
;
i
++
)
{
Py_ssize_t
incr
=
1
;
switch
(
s
[
i
])
{
switch
(
s
[
i
])
{
case
'\''
:
squotes
++
;
newsize
++
;
break
;
case
'\''
:
squotes
++
;
break
;
case
'"'
:
dquotes
++
;
newsize
++
;
break
;
case
'"'
:
dquotes
++
;
break
;
case
'\\'
:
case
'\t'
:
case
'\n'
:
case
'\r'
:
case
'\\'
:
case
'\t'
:
case
'\n'
:
case
'\r'
:
newsize
+
=
2
;
break
;
/* \C */
incr
=
2
;
break
;
/* \C */
default:
default:
if
(
s
[
i
]
<
' '
||
s
[
i
]
>=
0x7f
)
if
(
s
[
i
]
<
' '
||
s
[
i
]
>=
0x7f
)
newsize
+=
4
;
/* \xHH */
incr
=
4
;
/* \xHH */
else
newsize
++
;
}
}
if
(
newsize
>
PY_SSIZE_T_MAX
-
incr
)
goto
overflow
;
newsize
+=
incr
;
}
}
quote
=
'\''
;
quote
=
'\''
;
if
(
smartquotes
&&
squotes
&&
!
dquotes
)
if
(
smartquotes
&&
squotes
&&
!
dquotes
)
quote
=
'"'
;
quote
=
'"'
;
if
(
squotes
&&
quote
==
'\''
)
if
(
squotes
&&
quote
==
'\''
)
{
if
(
newsize
>
PY_SSIZE_T_MAX
-
squotes
)
goto
overflow
;
newsize
+=
squotes
;
newsize
+=
squotes
;
if
(
newsize
>
(
PY_SSIZE_T_MAX
-
sizeof
(
PyUnicodeObject
)
-
1
))
{
PyErr_SetString
(
PyExc_OverflowError
,
"bytes object is too large to make repr"
);
return
NULL
;
}
}
v
=
PyUnicode_New
(
newsize
,
127
);
v
=
PyUnicode_New
(
newsize
,
127
);
...
@@ -646,6 +645,11 @@ PyBytes_Repr(PyObject *obj, int smartquotes)
...
@@ -646,6 +645,11 @@ PyBytes_Repr(PyObject *obj, int smartquotes)
*
p
++
=
quote
;
*
p
++
=
quote
;
assert
(
_PyUnicode_CheckConsistency
(
v
,
1
));
assert
(
_PyUnicode_CheckConsistency
(
v
,
1
));
return
v
;
return
v
;
overflow:
PyErr_SetString
(
PyExc_OverflowError
,
"bytes object is too large to make repr"
);
return
NULL
;
}
}
static
PyObject
*
static
PyObject
*
...
...
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