Skip to content

PyLong_AsLongAndOverflow does not guarantee overflow is -1 when value is -1 #130824

Closed
@yijan4845

Description

@yijan4845

Bug report

Bug description:

In the function pylong_aslongandoverflow

static PyObject *
pylong_aslongandoverflow(PyObject *module, PyObject *arg)
{
NULLABLE(arg);
int overflow = UNINITIALIZED_INT;
long value = PyLong_AsLongAndOverflow(arg, &overflow);
if (value == -1 && PyErr_Occurred()) {
assert(overflow == -1);
return NULL;
}
return Py_BuildValue("li", value, overflow);
}

there is an assertion overflow == -1 when value == -1. But this is not always true, like if arg is NULL.

Reproduce:

from test.support import import_helper

_testlimitedcapi = import_helper.import_module('_testlimitedcapi')

aslonglongandoverflow = _testlimitedcapi.pylong_aslonglongandoverflow
aslonglongandoverflow(None)

Result:

python: ../Modules/_testlimitedcapi/long.c:674: pylong_aslonglongandoverflow: Assertion `overflow == -1' failed.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtopic-C-APItype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions