You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The S_unpack_from() function in Modules/_struct.c does not adequately
validate its arguments, potentially causing an out-of-bounds read
access. It should be noted that the check at line 1561 is inadequate for
obscene values of offset. Finally, because they're not really important
and I really don't want to type them all up-- you guys might want to go
through your code-- especially the modules and look for constructs where
an empty string will cause memory to be uninitialized-- look at the
audioop module for examples of what I mean-- the only thing that
actually saved you guys from overflows there was that the loops you
write with use the same variable.
What do you mean by "obscene" values? Do you have an example of actual
values where the check at line 1561 does not do the right thing?
-- just trying to understand where the problem is.
jnferguson commented on Apr 11, 2008
jnfergusonmannequin
MannequinAuthor
More actions
What I was originally thinking was if offset was larger than buf_len,
that would cause the check at 1561 to fail due to the subtraction. That
said, I'm not sure what type its being compared against so I need to
check this further, let me get back to you, I may have made a mistake
and this may be !bug.
All expressions are of type Py_ssize_t, which is signed.
buffer_len is positive; the subtraction (buffer_len - offset) can
overflow only if offset is a (large) negative number, but then the first
part of the test is already fulfilled.
Activity
jnferguson commentedon Apr 8, 2008
The S_unpack_from() function in Modules/_struct.c does not adequately
validate its arguments, potentially causing an out-of-bounds read
access. It should be noted that the check at line 1561 is inadequate for
obscene values of offset. Finally, because they're not really important
and I really don't want to type them all up-- you guys might want to go
through your code-- especially the modules and look for constructs where
an empty string will cause memory to be uninitialized-- look at the
audioop module for examples of what I mean-- the only thing that
actually saved you guys from overflows there was that the loops you
write with use the same variable.
1533 static PyObject *
1534 s_unpack_from(PyObject *self, PyObject *args, PyObject *kwds)
1535 {
1536 static char *kwlist[] = {"buffer", "offset", 0};
1537 #if (PY_VERSION_HEX < 0x02050000)
1538 static char *fmt = "z#|i:unpack_from";
1539 #else
1540 static char *fmt = "z#|n:unpack_from";
1541 #endif
1542 Py_ssize_t buffer_len = 0, offset = 0;
[...]
1547
1548 if (!PyArg_ParseTupleAndKeywords(args, kwds, fmt, kwlist,
1549 &buffer, &buffer_len,
&offset))
1550 return NULL;
[...]
1558 if (offset < 0)
1559 offset += buffer_len;
1560
1561 if (offset < 0 || (buffer_len - offset) < soself->s_size) {
[...]
1566 }
1567 return s_unpack_internal(soself, buffer + offset);
1568 }
amauryfa commentedon Apr 11, 2008
What do you mean by "obscene" values? Do you have an example of actual
values where the check at line 1561 does not do the right thing?
-- just trying to understand where the problem is.
jnferguson commentedon Apr 11, 2008
What I was originally thinking was if offset was larger than buf_len,
that would cause the check at 1561 to fail due to the subtraction. That
said, I'm not sure what type its being compared against so I need to
check this further, let me get back to you, I may have made a mistake
and this may be !bug.
gvanrossum commentedon Aug 5, 2008
Ping? Patch?
amauryfa commentedon Jun 3, 2009
All expressions are of type Py_ssize_t, which is signed.
buffer_len is positive; the subtraction (buffer_len - offset) can
overflow only if offset is a (large) negative number, but then the first
part of the test is already fulfilled.
Closing unless more evidence is given.