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

Skip to content

Commit 7ae251a

Browse files
committed
Fix out of bounds read in long_new() for empty bytes with an explicit base. int(b'', somebase) calls PyLong_FromString() with char* of length 1 but the function accesses the first argument at offset 1. CID 715359
2 parents 0ae066b + 79b97ee commit 7ae251a

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Objects/longobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4285,8 +4285,8 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
42854285
string = PyByteArray_AS_STRING(x);
42864286
else
42874287
string = PyBytes_AS_STRING(x);
4288-
if (strlen(string) != (size_t)size) {
4289-
/* We only see this if there's a null byte in x,
4288+
if (strlen(string) != (size_t)size || !size) {
4289+
/* We only see this if there's a null byte in x or x is empty,
42904290
x is a bytes or buffer, *and* a base is given. */
42914291
PyErr_Format(PyExc_ValueError,
42924292
"invalid literal for int() with base %d: %R",

0 commit comments

Comments
 (0)