Skip to content

Bug in PyObject_CopyData leads to incorrect data copying order #143737

@buxingtan

Description

@buxingtan

Bug report

Bug description:

version: python 3.14.2

/* Objects/abstract.c, function PyObject_CopyData, lines 727~732 */
    while (elements--) {
        _Py_add_one_to_index_C(view_src.ndim, indices, view_src.shape); /* WRONG: increment before copy */
        dptr = PyBuffer_GetPointer(&view_dest, indices);
        sptr = PyBuffer_GetPointer(&view_src, indices);
        memcpy(dptr, sptr, view_src.itemsize);
    }

maybe can change to

    while (elements--) {
        dptr = PyBuffer_GetPointer(&view_dest, indices);
        sptr = PyBuffer_GetPointer(&view_src, indices);
        memcpy(dptr, sptr, view_src.itemsize);
        _Py_add_one_to_index_C(view_src.ndim, indices, view_src.shape);
    }

I don't know which other versions, besides version 3.14.2, are involved with this code.

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions