PyLong_FromString() does not always set *pend
on error
#110865
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-C-API
type-bug
An unexpected behavior, bug, or error
According to the documentation,
PyLong_FromString()
sets*pend
(ifpend
is not NULL) to the first character that could not be processed on error. But it does not do this in the following cases:base
is invalid (not 0 or in range from 2 to 36).sys.maxsize
bits.sys.get_int_max_str_digits()
._pylong.int_from_string()
is used.The workaround is to initialize the pointer to some known value, for example the start of the string or NULL before using
PyLong_FromString()
. If initialize it to NULL, we can distinguish ValueError raised for invalidbase
or exceeding thesys.get_int_max_str_digits()
limit from ValueError raised for invalid string content.We should either document this and require initialization of the end pointer, or always set it on error in
PyLong_FromString()
. The latter is a potentially breaking change, because it can override the sentinel value used in the user code. But the former looks like bad design.The text was updated successfully, but these errors were encountered: