[docs] [issue26198] PyArg_ParseTuple with format "et#" and "es#" detects overflow by raising TypeError instead of ValueError
report at bugs.python.org
Mon Jan 25 11:13:08 EST 2016
New submission from Hrvoje Nikšić:
The documentation for the "es#" format (and the "et#" that derives from it) documents the possibility of providing an already allocated buffer. Buffer overflow is detected and handled as follows: "If the buffer is not large enough, a ValueError will be set."
However, the actual behavior is to raise a TypeError. Inspecting the code in getargs.c reveals that convertsimple() handles buffer overflow by returning a formatted message to its caller, convertitem(). Calls to convertitem() that return an error call seterror() to set the error, and seterror() unconditionally sets the PyExc_TypeError.
This is not a big issue in practice, and since the behavior is not new, it might be best to simply update the documentation to match the existing practice instead of changing the behavior and risking breaking working code.
assignee: docs at python
components: Documentation, Interpreter Core
nosy: docs at python, hniksic
title: PyArg_ParseTuple with format "et#" and "es#" detects overflow by raising TypeError instead of ValueError
versions: Python 2.7, Python 3.5
Python tracker <report at bugs.python.org>
More information about the docs