mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Issue #16475 : Correctly handle the EOF when reading marshal streams.
This commit is contained in:
parent
e178187bf6
commit
6168362509
2 changed files with 14 additions and 9 deletions
|
@ -283,6 +283,11 @@ class BugsTestCase(unittest.TestCase):
|
||||||
unicode_string = 'T'
|
unicode_string = 'T'
|
||||||
self.assertRaises(TypeError, marshal.loads, unicode_string)
|
self.assertRaises(TypeError, marshal.loads, unicode_string)
|
||||||
|
|
||||||
|
def _test_eof(self):
|
||||||
|
data = marshal.dumps(("hello", "dolly", None))
|
||||||
|
for i in range(len(data)):
|
||||||
|
self.assertRaises(EOFError, marshal.loads, data[0: i])
|
||||||
|
|
||||||
LARGE_SIZE = 2**31
|
LARGE_SIZE = 2**31
|
||||||
pointer_size = 8 if sys.maxsize > 0xFFFFFFFF else 4
|
pointer_size = 8 if sys.maxsize > 0xFFFFFFFF else 4
|
||||||
|
|
||||||
|
|
|
@ -808,10 +808,16 @@ r_object(RFILE *p)
|
||||||
PyObject *v, *v2;
|
PyObject *v, *v2;
|
||||||
Py_ssize_t idx = 0;
|
Py_ssize_t idx = 0;
|
||||||
long i, n;
|
long i, n;
|
||||||
int type = r_byte(p);
|
int type, code = r_byte(p);
|
||||||
int flag;
|
int flag;
|
||||||
PyObject *retval;
|
PyObject *retval;
|
||||||
|
|
||||||
|
if (code == EOF) {
|
||||||
|
PyErr_SetString(PyExc_EOFError,
|
||||||
|
"EOF read where object expected");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
p->depth++;
|
p->depth++;
|
||||||
|
|
||||||
if (p->depth > MAX_MARSHAL_STACK_DEPTH) {
|
if (p->depth > MAX_MARSHAL_STACK_DEPTH) {
|
||||||
|
@ -820,8 +826,8 @@ r_object(RFILE *p)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
flag = type & FLAG_REF;
|
flag = code & FLAG_REF;
|
||||||
type = type & ~FLAG_REF;
|
type = code & ~FLAG_REF;
|
||||||
|
|
||||||
#define R_REF(O) do{\
|
#define R_REF(O) do{\
|
||||||
if (flag) \
|
if (flag) \
|
||||||
|
@ -830,12 +836,6 @@ r_object(RFILE *p)
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
case EOF:
|
|
||||||
PyErr_SetString(PyExc_EOFError,
|
|
||||||
"EOF read where object expected");
|
|
||||||
retval = NULL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TYPE_NULL:
|
case TYPE_NULL:
|
||||||
retval = NULL;
|
retval = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue