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
When PyArg_ParseTuple correctly parses a s* format, but raises an
exception afterwards (for a subsequent parameter), the user code will
not call PyBuffer_Release() and memory will leak.
Seen by "regrtest -R:: test_binascii"
For example:
>>> binascii.a2b_qp("", **{1:1})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: keywords must be strings
[42278 refs]
>>> binascii.a2b_qp("", **{1:1})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: keywords must be strings
[42279 refs]
>>> binascii.a2b_qp("", **{1:1})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: keywords must be strings
[42280 refs]
The same pattern was correctly handled by the "et#" type (where the user
has to call PyMem_Free) with the help of a cleanup list (see the
addcleanup() function in getargs.c). (See bpo-501716)
By the way, this bug affects 2.6 as well, although not in binascii since
it has not been converted to use "s*":
>>> codecs.latin_1_decode(b"", 0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: latin_1_decode() argument 2 must be string or None, not int
[57425 refs]
>>> codecs.latin_1_decode(b"", 0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: latin_1_decode() argument 2 must be string or None, not int
[57426 refs]
Activity
amauryfa commentedon Aug 24, 2008
When PyArg_ParseTuple correctly parses a s* format, but raises an
exception afterwards (for a subsequent parameter), the user code will
not call PyBuffer_Release() and memory will leak.
Seen by "regrtest -R:: test_binascii"
The same pattern was correctly handled by the "et#" type (where the user
has to call PyMem_Free) with the help of a cleanup list (see the
addcleanup() function in getargs.c). (See bpo-501716)
pitrou commentedon Aug 25, 2008
Here is a patch. Please review.
amauryfa commentedon Aug 25, 2008
This patch elegantly reuses the existing cleanup list.
Only two remarks:
intead of
addcleanup(*buffer, freelist, NULL);
I'd prefer
addcleanup(*buffer, freelist, cleanup_ptr);
pitrou commentedon Aug 25, 2008
Ok, here is a new patch addressing Amaury's comments.
pitrou commentedon Aug 25, 2008
By the way, this bug affects 2.6 as well, although not in binascii since
it has not been converted to use "s*":
pitrou commentedon Aug 25, 2008
Here is a patch for 2.6.
amauryfa commentedon Aug 25, 2008
Both patches look good to me.
pitrou commentedon Aug 25, 2008
Actually, here is a better patch for py3k.
pitrou commentedon Aug 25, 2008
And a similarly better patch for 2.6.
pitrou commentedon Aug 29, 2008
Amaury, are these patches ok to check in?
amauryfa commentedon Aug 29, 2008
Yes, let them go in!
pitrou commentedon Aug 29, 2008
Committed in r66057 and r66058.