[issue31243] checks whether PyArg_ParseTuple returned a negative int
Oren Milman
report at bugs.python.org
Mon Aug 21 04:33:09 EDT 2017
New submission from Oren Milman:
according to the docs (https://docs.python.org/3.7/c-api/arg.html?highlight=pyarg_parsetuple#c.PyArg_ParseTuple), PyArg_ParseTuple
returns true for success or false for failure. I also looked at the
implementation in Python/getargs.c, and it seems that indeed PyArg_ParseTuple
can return only 0 or 1.
however, in some places in the codebase, there are checks whether
PyArg_ParseTuple returned a negative int.
I found a bunch in Modules/_testcapimodule.c, and one in Modules/_io/textio.c
in textiowrapper_read_chunk. (hopefully i haven't missed other places.)
this code crashes because of the check in textiowrapper_read_chunk:
import codecs
import _io
class MyDec():
def getstate(self):
return 420
class MyDecWrapper():
def __call__(self, blabla):
return MyDec()
quopri = codecs.lookup("quopri")
quopri._is_text_encoding = True
quopri.incrementaldecoder = MyDecWrapper()
t = _io.TextIOWrapper(_io.BytesIO(b'aaaaaa'),
newline='\n', encoding="quopri")
t.read(42)
I guess all of these checks should be changed to check whether PyArg_ParseTuple
returned 0.
also, before this specific call to PyArg_ParseTuple in textiowrapper_read_chunk,
we should check whether 'state' is a tuple.
Moreover, this call shouldn't produce a wrong error message, as explained in
#28261.
----------
components: Interpreter Core
messages: 300613
nosy: Oren Milman
priority: normal
severity: normal
status: open
title: checks whether PyArg_ParseTuple returned a negative int
type: crash
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue31243>
_______________________________________
More information about the Python-bugs-list
mailing list