Skip to content

BUFFER_NEW macro: unchecked malloc inside GIL-released region #529

@devdanzin

Description

@devdanzin

The BUFFER_NEW(dtype) macro expands to dtype *B = malloc(LENGTH * sizeof(dtype)); with no NULL check. B is immediately used in the sorting algorithm inside a BN_BEGIN_ALLOW_THREADS block (GIL released), so a NULL dereference cannot even set a Python exception — it's a bare segfault. Four instances (one per dtype in argpartition).

File(s): nonreduce_axis_template.c (BUFFER_NEW definition), used at generated lines 266, 295, 324, 353 in nonreduce_axis.c

See #518 for the complete report.

Found using cext-review-toolkit.

Metadata

Metadata

Assignees

No one assigned

    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