Skip to content

Regression in integer power (C extension type) for GraalPy 25.0 #551

@skirpichev

Description

@skirpichev

Trying to update GraalPy in CI of my project (diofant/python-gmp#261) I got a crash, that seems to be related with the following test (working fine before):

    with pytest.raises(MemoryError):
        pow(mpz(123), 111111111111111111)

Relevant extension code looks like this:

static PyObject *
power(PyObject *self, PyObject *other, PyObject *module)
{
    MPZ_Object *res = NULL;
    MPZ_Object *u = NULL, *v = NULL;

    CHECK_OP(u, self);
    CHECK_OP(v, other);
    if (Py_IsNone(module)) {
...
        res = MPZ_new(0);

        int64_t exp;

        if (!res || zz_to_i64(&v->z, &exp)
            || zz_pow(&u->z, (uint64_t)exp, &res->z))
        {   
            /* LCOV_EXCL_START */
            Py_CLEAR(res);
            PyErr_SetNone(PyExc_MemoryError);
            /* LCOV_EXCL_STOP */
        }
        Py_DECREF(u);
        Py_DECREF(v);
        return (PyObject *)res;
    }
...
}

So, I guess something nasty happens with Py_CLEAR or PyErr_SetNone...

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions