mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
Fix bug
[ 1180997 ] lax error-checking in new-in-2.4 marshal stuff which I'd assigned to Martin, but actually turned out to be easy to fix. Also, a test.
This commit is contained in:
parent
01fca11080
commit
f2ca5af439
2 changed files with 13 additions and 0 deletions
|
@ -211,6 +211,15 @@ class BugsTestCase(unittest.TestCase):
|
|||
self.assertEquals(marshal.loads(marshal.dumps(5, 0)), 5)
|
||||
self.assertEquals(marshal.loads(marshal.dumps(5, 1)), 5)
|
||||
|
||||
def test_fuzz(self):
|
||||
# simple test that it's at least not *totally* trivial to
|
||||
# crash from bad marshal data
|
||||
for c in [chr(i) for i in range(256)]:
|
||||
try:
|
||||
marshal.loads(c)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def test_main():
|
||||
test_support.run_unittest(IntTestCase,
|
||||
FloatTestCase,
|
||||
|
|
|
@ -648,6 +648,10 @@ r_object(RFILE *p)
|
|||
|
||||
case TYPE_STRINGREF:
|
||||
n = r_long(p);
|
||||
if (n < 0 || n >= PyList_GET_SIZE(p->strings)) {
|
||||
PyErr_SetString(PyExc_ValueError, "bad marshal data");
|
||||
return NULL;
|
||||
}
|
||||
v = PyList_GET_ITEM(p->strings, n);
|
||||
Py_INCREF(v);
|
||||
return v;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue