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
e3bfe193
Commit
e3bfe193
authored
Feb 01, 2015
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix possible overflow in encode_basestring_ascii (closes #23369)
parent
4dbc3050
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
5 deletions
+25
-5
Lib/test/test_json/test_encode_basestring_ascii.py
Lib/test/test_json/test_encode_basestring_ascii.py
+8
-1
Misc/NEWS
Misc/NEWS
+6
-0
Modules/_json.c
Modules/_json.c
+11
-4
No files found.
Lib/test/test_json/test_encode_basestring_ascii.py
View file @
e3bfe193
from
collections
import
OrderedDict
from
test.test_json
import
PyTest
,
CTest
from
test.support
import
bigaddrspacetest
CASES
=
[
...
...
@@ -41,4 +42,10 @@ class TestEncodeBasestringAscii:
class
TestPyEncodeBasestringAscii
(
TestEncodeBasestringAscii
,
PyTest
):
pass
class
TestCEncodeBasestringAscii
(
TestEncodeBasestringAscii
,
CTest
):
pass
class
TestCEncodeBasestringAscii
(
TestEncodeBasestringAscii
,
CTest
):
@
bigaddrspacetest
def
test_overflow
(
self
):
s
=
"
\
uffff
"
*
((
2
**
32
)
//
6
+
1
)
with
self
.
assertRaises
(
OverflowError
):
self
.
json
.
encoder
.
encode_basestring_ascii
(
s
)
Misc/NEWS
View file @
e3bfe193
...
...
@@ -13,6 +13,12 @@ Core and Builtins
- Issue #23055: Fixed a buffer overflow in PyUnicode_FromFormatV. Analysis
and fix by Guido Vranken.
Library
-------
- Issue #23369: Fixed possible integer overflow in
_json.encode_basestring_ascii.
What'
s
New
in
Python
3.3.6
?
===========================
...
...
Modules/_json.c
View file @
e3bfe193
...
...
@@ -216,17 +216,24 @@ ascii_escape_unicode(PyObject *pystr)
/* Compute the output size */
for
(
i
=
0
,
output_size
=
2
;
i
<
input_chars
;
i
++
)
{
Py_UCS4
c
=
PyUnicode_READ
(
kind
,
input
,
i
);
if
(
S_CHAR
(
c
))
output_size
++
;
Py_ssize_t
d
;
if
(
S_CHAR
(
c
))
{
d
=
1
;
}
else
{
switch
(
c
)
{
case
'\\'
:
case
'"'
:
case
'\b'
:
case
'\f'
:
case
'\n'
:
case
'\r'
:
case
'\t'
:
output_size
+
=
2
;
break
;
d
=
2
;
break
;
default:
output_size
+
=
c
>=
0x10000
?
12
:
6
;
d
=
c
>=
0x10000
?
12
:
6
;
}
}
if
(
output_size
>
PY_SSIZE_T_MAX
-
d
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"string is too long to escape"
);
return
NULL
;
}
output_size
+=
d
;
}
rval
=
PyUnicode_New
(
output_size
,
127
);
...
...
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