Skip to content

PyObject_CallFunction generates MemoryError when format string is iy# and buffer is on stack #123734

@pkrn-ams-osram

Description

@pkrn-ams-osram

Bug report

Bug description:

Using Python 3.12.5 on Windows, the executable built from the following C code produces the output MemoryError:

#define PY_SSIZE_T_CLEAN
#include <Python.h>

int main(int argc, char *argv[])
{
    Py_Initialize();

    const char *python_code =
        "def func(*args):\n"
        "    print(args)\n";
    PyRun_SimpleString(python_code);

    PyObject *main_module = PyImport_AddModule("__main__");
    PyObject *main_dict = PyModule_GetDict(main_module);

    PyObject *func = PyDict_GetItemString(main_dict, "func");

    char data[10] = {0};
    PyObject *result = PyObject_CallFunction(func, "iy#", 1, data, 10);
    if (!result)
    {
        PyErr_Print();
    }

    Py_Finalize();

    return 0;
}

The error does not occur when the data variable is made a global variable. I am using GCC 13.10.0 (MinGW-Builds project) on x86-64 Windows 10. I cannot attach the binary to this issue due to GitHub file type restrictions, but please let me know if I should provide it to you via a different channel.

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions