mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +00:00
Merged revisions 75141 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r75141 | mark.dickinson | 2009-09-29 20:01:06 +0100 (Tue, 29 Sep 2009) | 3 lines Issue #7019: Unmarshalling of bad long data could produce unnormalized PyLongs. Raise ValueError instead. ........
This commit is contained in:
parent
ead1d62d32
commit
2683ab04a6
3 changed files with 21 additions and 3 deletions
|
@ -212,6 +212,11 @@ class BugsTestCase(unittest.TestCase):
|
||||||
testString = 'abc' * size
|
testString = 'abc' * size
|
||||||
marshal.dumps(testString)
|
marshal.dumps(testString)
|
||||||
|
|
||||||
|
def test_invalid_longs(self):
|
||||||
|
# Issue #7019: marshal.loads shouldn't produce unnormalized PyLongs
|
||||||
|
invalid_string = b'l\x02\x00\x00\x00\x00\x00\x00\x00'
|
||||||
|
self.assertRaises(ValueError, marshal.loads, invalid_string)
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
support.run_unittest(IntTestCase,
|
support.run_unittest(IntTestCase,
|
||||||
|
|
|
@ -12,6 +12,9 @@ What's New in Python 3.2 Alpha 1?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #7019: Raise ValueError when unmarshalling bad long data, instead
|
||||||
|
of producing internally inconsistent Python longs.
|
||||||
|
|
||||||
- Issue #6990: Fix threading.local subclasses leaving old state around
|
- Issue #6990: Fix threading.local subclasses leaving old state around
|
||||||
after a reference cycle GC which could be recycled by new locals.
|
after a reference cycle GC which could be recycled by new locals.
|
||||||
|
|
||||||
|
|
|
@ -553,7 +553,7 @@ static PyObject *
|
||||||
r_PyLong(RFILE *p)
|
r_PyLong(RFILE *p)
|
||||||
{
|
{
|
||||||
PyLongObject *ob;
|
PyLongObject *ob;
|
||||||
int size, i, j, md;
|
int size, i, j, md, shorts_in_top_digit;
|
||||||
long n;
|
long n;
|
||||||
digit d;
|
digit d;
|
||||||
|
|
||||||
|
@ -566,7 +566,8 @@ r_PyLong(RFILE *p)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = 1 + (ABS(n)-1) / PyLong_MARSHAL_RATIO;
|
size = 1 + (ABS(n) - 1) / PyLong_MARSHAL_RATIO;
|
||||||
|
shorts_in_top_digit = 1 + (ABS(n) - 1) % PyLong_MARSHAL_RATIO;
|
||||||
ob = _PyLong_New(size);
|
ob = _PyLong_New(size);
|
||||||
if (ob == NULL)
|
if (ob == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -583,12 +584,21 @@ r_PyLong(RFILE *p)
|
||||||
ob->ob_digit[i] = d;
|
ob->ob_digit[i] = d;
|
||||||
}
|
}
|
||||||
d = 0;
|
d = 0;
|
||||||
for (j=0; j < (ABS(n)-1)%PyLong_MARSHAL_RATIO + 1; j++) {
|
for (j=0; j < shorts_in_top_digit; j++) {
|
||||||
md = r_short(p);
|
md = r_short(p);
|
||||||
if (md < 0 || md > PyLong_MARSHAL_BASE)
|
if (md < 0 || md > PyLong_MARSHAL_BASE)
|
||||||
goto bad_digit;
|
goto bad_digit;
|
||||||
|
/* topmost marshal digit should be nonzero */
|
||||||
|
if (md == 0 && j == shorts_in_top_digit - 1) {
|
||||||
|
Py_DECREF(ob);
|
||||||
|
PyErr_SetString(PyExc_ValueError,
|
||||||
|
"bad marshal data (unnormalized long data)");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
d += (digit)md << j*PyLong_MARSHAL_SHIFT;
|
d += (digit)md << j*PyLong_MARSHAL_SHIFT;
|
||||||
}
|
}
|
||||||
|
/* top digit should be nonzero, else the resulting PyLong won't be
|
||||||
|
normalized */
|
||||||
ob->ob_digit[size-1] = d;
|
ob->ob_digit[size-1] = d;
|
||||||
return (PyObject *)ob;
|
return (PyObject *)ob;
|
||||||
bad_digit:
|
bad_digit:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue