Skip to content

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

Closed

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]

Activity

  1. grlee77 commented on Jun 24, 2021

    @grlee77
    ContributorAuthor

    It seems that the line mentioned in the segfault corrurs when trying to access the base attribute:
    given_descrs[0]->subarray->base, but given_descrs[0]->subarray is NULL

  2. added this to the 1.21.1 release milestone on Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions