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
53d36b69
Commit
53d36b69
authored
Nov 01, 2012
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Plain Diff
Issue #16228: Fix a crash in the json module where a list changes size while it is being encoded.
Patch by Serhiy Storchaka.
parents
1511a5a3
5ebe65f8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
7 deletions
+14
-7
Lib/test/json_tests/test_dump.py
Lib/test/json_tests/test_dump.py
+8
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_json.c
Modules/_json.c
+3
-7
No files found.
Lib/test/json_tests/test_dump.py
View file @
53d36b69
...
...
@@ -20,6 +20,14 @@ class TestDump:
{
2
:
3.0
,
4.0
:
5
,
False
:
1
,
6
:
True
},
sort_keys
=
True
),
'{"false": 1, "2": 3.0, "4.0": 5, "6": true}'
)
# Issue 16228: Crash on encoding resized list
def
test_encode_mutated
(
self
):
a
=
[
object
()]
*
10
def
crasher
(
obj
):
del
a
[
-
1
]
self
.
assertEqual
(
self
.
dumps
(
a
,
default
=
crasher
),
'[null, null, null, null, null]'
)
class
TestPyDump
(
TestDump
,
PyTest
):
pass
...
...
Misc/NEWS
View file @
53d36b69
...
...
@@ -85,6 +85,9 @@ Core and Builtins
Library
-------
- Issue #16228: Fix a crash in the json module where a list changes size
while it is being encoded. Patch by Serhiy Storchaka.
- Issue #16351: New function gc.get_stats() returns per-generation collection
statistics.
...
...
Modules/_json.c
View file @
53d36b69
...
...
@@ -1659,8 +1659,6 @@ encoder_listencode_list(PyEncoderObject *s, _PyAccu *acc,
static
PyObject
*
empty_array
=
NULL
;
PyObject
*
ident
=
NULL
;
PyObject
*
s_fast
=
NULL
;
Py_ssize_t
num_items
;
PyObject
**
seq_items
;
Py_ssize_t
i
;
if
(
open_array
==
NULL
||
close_array
==
NULL
||
empty_array
==
NULL
)
{
...
...
@@ -1674,8 +1672,7 @@ encoder_listencode_list(PyEncoderObject *s, _PyAccu *acc,
s_fast
=
PySequence_Fast
(
seq
,
"_iterencode_list needs a sequence"
);
if
(
s_fast
==
NULL
)
return
-
1
;
num_items
=
PySequence_Fast_GET_SIZE
(
s_fast
);
if
(
num_items
==
0
)
{
if
(
PySequence_Fast_GET_SIZE
(
s_fast
)
==
0
)
{
Py_DECREF
(
s_fast
);
return
_PyAccu_Accumulate
(
acc
,
empty_array
);
}
...
...
@@ -1696,7 +1693,6 @@ encoder_listencode_list(PyEncoderObject *s, _PyAccu *acc,
}
}
seq_items
=
PySequence_Fast_ITEMS
(
s_fast
);
if
(
_PyAccu_Accumulate
(
acc
,
open_array
))
goto
bail
;
if
(
s
->
indent
!=
Py_None
)
{
...
...
@@ -1708,8 +1704,8 @@ encoder_listencode_list(PyEncoderObject *s, _PyAccu *acc,
buf += newline_indent
*/
}
for
(
i
=
0
;
i
<
num_items
;
i
++
)
{
PyObject
*
obj
=
seq_items
[
i
]
;
for
(
i
=
0
;
i
<
PySequence_Fast_GET_SIZE
(
s_fast
)
;
i
++
)
{
PyObject
*
obj
=
PySequence_Fast_GET_ITEM
(
s_fast
,
i
)
;
if
(
i
)
{
if
(
_PyAccu_Accumulate
(
acc
,
s
->
item_separator
))
goto
bail
;
...
...
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