Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 781eba7

Browse files
committed
Merged revisions 76708 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r76708 | antoine.pitrou | 2009-12-08 16:40:51 +0100 (mar., 08 déc. 2009) | 4 lines Issue #6986: Fix crash in the JSON C accelerator when called with the wrong parameter types. Patch by Victor Stinner. ........
1 parent b88a496 commit 781eba7

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

Lib/json/tests/test_speedups.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import decimal
22
from unittest import TestCase
33

4-
from json import decoder
5-
from json import encoder
4+
from json import decoder, encoder, scanner
65

76
class TestSpeedups(TestCase):
87
def test_scanstring(self):
@@ -13,3 +12,13 @@ def test_encode_basestring_ascii(self):
1312
self.assertEquals(encoder.encode_basestring_ascii.__module__, "_json")
1413
self.assertTrue(encoder.encode_basestring_ascii is
1514
encoder.c_encode_basestring_ascii)
15+
16+
class TestDecode(TestCase):
17+
def test_make_scanner(self):
18+
self.assertRaises(AttributeError, scanner.c_make_scanner, 1)
19+
20+
def test_make_encoder(self):
21+
self.assertRaises(TypeError, encoder.c_make_encoder,
22+
(True, False),
23+
b"\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75",
24+
None)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ C-API
154154
Library
155155
-------
156156

157+
- Issue #6986: Fix crash in the JSON C accelerator when called with the
158+
wrong parameter types. Patch by Victor Stinner.
159+
157160
- Issue #7457: added a read_pkg_file method to
158161
distutils.dist.DistributionMetadata.
159162

Modules/_json.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,15 +1123,28 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
11231123
static char *kwlist[] = {"markers", "default", "encoder", "indent", "key_separator", "item_separator", "sort_keys", "skipkeys", "allow_nan", NULL};
11241124

11251125
PyEncoderObject *s;
1126-
PyObject *allow_nan;
1126+
PyObject *markers, *defaultfn, *encoder, *indent, *key_separator;
1127+
PyObject *item_separator, *sort_keys, *skipkeys, *allow_nan;
11271128

11281129
assert(PyEncoder_Check(self));
11291130
s = (PyEncoderObject *)self;
11301131

11311132
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOOOOOO:make_encoder", kwlist,
1132-
&s->markers, &s->defaultfn, &s->encoder, &s->indent, &s->key_separator, &s->item_separator, &s->sort_keys, &s->skipkeys, &allow_nan))
1133+
&markers, &defaultfn, &encoder, &indent, &key_separator, &item_separator,
1134+
&sort_keys, &skipkeys, &allow_nan))
11331135
return -1;
11341136

1137+
s->markers = markers;
1138+
s->defaultfn = defaultfn;
1139+
s->encoder = encoder;
1140+
s->indent = indent;
1141+
s->key_separator = key_separator;
1142+
s->item_separator = item_separator;
1143+
s->sort_keys = sort_keys;
1144+
s->skipkeys = skipkeys;
1145+
s->fast_encode = (PyCFunction_Check(s->encoder) && PyCFunction_GetFunction(s->encoder) == (PyCFunction)py_encode_basestring_ascii);
1146+
s->allow_nan = PyObject_IsTrue(allow_nan);
1147+
11351148
Py_INCREF(s->markers);
11361149
Py_INCREF(s->defaultfn);
11371150
Py_INCREF(s->encoder);
@@ -1140,8 +1153,6 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
11401153
Py_INCREF(s->item_separator);
11411154
Py_INCREF(s->sort_keys);
11421155
Py_INCREF(s->skipkeys);
1143-
s->fast_encode = (PyCFunction_Check(s->encoder) && PyCFunction_GetFunction(s->encoder) == (PyCFunction)py_encode_basestring_ascii);
1144-
s->allow_nan = PyObject_IsTrue(allow_nan);
11451156
return 0;
11461157
}
11471158

0 commit comments

Comments
 (0)