mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Issue #19437: Fix r_PyLong() of marshal module, stop immediatly at first
failure, don't read any more data
This commit is contained in:
parent
a9eb38f02a
commit
763b0d19c9
1 changed files with 11 additions and 4 deletions
|
@ -612,6 +612,7 @@ r_string(Py_ssize_t n, RFILE *p)
|
||||||
}
|
}
|
||||||
p->buf_size = n;
|
p->buf_size = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!p->readable) {
|
if (!p->readable) {
|
||||||
assert(p->fp != NULL);
|
assert(p->fp != NULL);
|
||||||
read = fread(p->buf, 1, n, p->fp);
|
read = fread(p->buf, 1, n, p->fp);
|
||||||
|
@ -731,25 +732,31 @@ r_PyLong(RFILE *p)
|
||||||
ob = _PyLong_New(size);
|
ob = _PyLong_New(size);
|
||||||
if (ob == NULL)
|
if (ob == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
Py_SIZE(ob) = n > 0 ? size : -size;
|
Py_SIZE(ob) = n > 0 ? size : -size;
|
||||||
|
|
||||||
for (i = 0; i < size-1; i++) {
|
for (i = 0; i < size-1; i++) {
|
||||||
d = 0;
|
d = 0;
|
||||||
for (j=0; j < PyLong_MARSHAL_RATIO; j++) {
|
for (j=0; j < PyLong_MARSHAL_RATIO; j++) {
|
||||||
md = r_short(p);
|
md = r_short(p);
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred()) {
|
||||||
break;
|
Py_DECREF(ob);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (md < 0 || md > PyLong_MARSHAL_BASE)
|
if (md < 0 || md > PyLong_MARSHAL_BASE)
|
||||||
goto bad_digit;
|
goto bad_digit;
|
||||||
d += (digit)md << j*PyLong_MARSHAL_SHIFT;
|
d += (digit)md << j*PyLong_MARSHAL_SHIFT;
|
||||||
}
|
}
|
||||||
ob->ob_digit[i] = d;
|
ob->ob_digit[i] = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
d = 0;
|
d = 0;
|
||||||
for (j=0; j < shorts_in_top_digit; j++) {
|
for (j=0; j < shorts_in_top_digit; j++) {
|
||||||
md = r_short(p);
|
md = r_short(p);
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred()) {
|
||||||
break;
|
Py_DECREF(ob);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
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 */
|
/* topmost marshal digit should be nonzero */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue