Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
f8d6fd60
Kaydet (Commit)
f8d6fd60
authored
May 10, 2011
tarafından
Ezio Melotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
#12051: merge with 3.2.
üst
19474770
f188bc5d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
3 deletions
+39
-3
test_recursion.py
Lib/test/json_tests/test_recursion.py
+21
-1
NEWS
Misc/NEWS
+3
-0
_json.c
Modules/_json.c
+15
-2
No files found.
Lib/test/json_tests/test_recursion.py
Dosyayı görüntüle @
f8d6fd60
...
...
@@ -16,6 +16,11 @@ class RecursiveJSONEncoder(json.JSONEncoder):
return
'JSONTestObject'
return
json
.
JSONEncoder
.
default
(
o
)
class
EndlessJSONEncoder
(
json
.
JSONEncoder
):
def
default
(
self
,
o
):
"""If check_circular is False, this will keep adding another list."""
return
[
o
]
class
TestRecursion
(
TestCase
):
def
test_listrecursion
(
self
):
...
...
@@ -67,7 +72,7 @@ class TestRecursion(TestCase):
self
.
fail
(
"didn't raise ValueError on default recursion"
)
def
test_highly_nested_objects
(
self
):
def
test_highly_nested_objects
_decoding
(
self
):
# test that loading highly-nested objects doesn't segfault when C
# accelerations are used. See #12017
with
self
.
assertRaises
(
RuntimeError
):
...
...
@@ -76,3 +81,18 @@ class TestRecursion(TestCase):
json
.
loads
(
'{"a":'
*
100000
+
'[1]'
+
'}'
*
100000
)
with
self
.
assertRaises
(
RuntimeError
):
json
.
loads
(
'['
*
100000
+
'1'
+
']'
*
100000
)
def
test_highly_nested_objects_encoding
(
self
):
# See #12051
l
,
d
=
[],
{}
for
x
in
range
(
100000
):
l
,
d
=
[
l
],
{
'k'
:
d
}
with
self
.
assertRaises
(
RuntimeError
):
json
.
dumps
(
l
)
with
self
.
assertRaises
(
RuntimeError
):
json
.
dumps
(
d
)
def
test_endless_recursion
(
self
):
# See #12051
with
self
.
assertRaises
(
RuntimeError
):
EndlessJSONEncoder
(
check_circular
=
False
)
.
encode
(
5
j
)
Misc/NEWS
Dosyayı görüntüle @
f8d6fd60
...
...
@@ -624,6 +624,9 @@ Tools/Demos
Extension Modules
-----------------
- Issue #12051: Fix segfault in json.dumps() while encoding highly-nested
objects using the C accelerations.
- Issue #12017: Fix segfault in json.loads() while decoding highly-nested
objects using the C accelerations.
...
...
Modules/_json.c
Dosyayı görüntüle @
f8d6fd60
...
...
@@ -1354,10 +1354,18 @@ encoder_listencode_obj(PyEncoderObject *s, PyObject *rval, PyObject *obj, Py_ssi
return
_steal_list_append
(
rval
,
encoded
);
}
else
if
(
PyList_Check
(
obj
)
||
PyTuple_Check
(
obj
))
{
return
encoder_listencode_list
(
s
,
rval
,
obj
,
indent_level
);
if
(
Py_EnterRecursiveCall
(
" while encoding a JSON object"
))
return
-
1
;
rv
=
encoder_listencode_list
(
s
,
rval
,
obj
,
indent_level
);
Py_LeaveRecursiveCall
();
return
rv
;
}
else
if
(
PyDict_Check
(
obj
))
{
return
encoder_listencode_dict
(
s
,
rval
,
obj
,
indent_level
);
if
(
Py_EnterRecursiveCall
(
" while encoding a JSON object"
))
return
-
1
;
rv
=
encoder_listencode_dict
(
s
,
rval
,
obj
,
indent_level
);
Py_LeaveRecursiveCall
();
return
rv
;
}
else
{
PyObject
*
ident
=
NULL
;
...
...
@@ -1383,7 +1391,12 @@ encoder_listencode_obj(PyEncoderObject *s, PyObject *rval, PyObject *obj, Py_ssi
Py_XDECREF
(
ident
);
return
-
1
;
}
if
(
Py_EnterRecursiveCall
(
" while encoding a JSON object"
))
return
-
1
;
rv
=
encoder_listencode_obj
(
s
,
rval
,
newobj
,
indent_level
);
Py_LeaveRecursiveCall
();
Py_DECREF
(
newobj
);
if
(
rv
)
{
Py_XDECREF
(
ident
);
...
...
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