Skip to content

dtype-related segfault when taking a view in NumPy 1.21 #19325

@grlee77

Description

@grlee77

I am seeing a segfault in the zarr-python test suite when using NumPy 1.21. It appears to be related to taking a view of an array with void type:

Reproducing code example:

Here is a small reproducer independent of Zarr:

import numpy as np

dtype = np.dtype([('foo', '<i8'), ('bar', [('foo', '<i4'), ('bar', '<f4', (3, 2)), ('baz', 'u1')]), ('baz', 'S3')])

x = np.array(b'', dtype=dtype.str)

x.view(dtype)  # segfault

In 1.20.3 the output of the code above is:

array((0, (0, [[0., 0.], [0., 0.], [0., 0.]], 0), b''),
      dtype=[('foo', '<i8'), ('bar', [('foo', '<i4'), ('bar', '<f4', (3, 2)), ('baz', 'u1')]), ('baz', 'S3')])

Error message:

thread 1 "python" received signal SIGSEGV, Segmentation fault.
void_to_void_resolve_descriptors (self=0x7fffc50451b0, dtypes=0x7fffffffc120, given_descrs=0x7fffffffc090, loop_descrs=0x7fffffffc0a0) at numpy/core/src/multiarray/convert_datatype.c:3296
3296	        NPY_CASTING field_casting = PyArray_GetCastSafety(

NumPy/Python version information:

1.21.0 3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 16:07:37)
[GCC 9.3.0]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions