Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BUG: numpy.asarray's boundary check fails with too large shape and got a segmentation fault #27949

Copy link
Copy link
Closed
@EgodPrime

Description

@EgodPrime
Issue body actions

Describe the issue:

Actually, I first triggered this Segmentation Fault when calling np.lib.stride_tricks.as_strided. After reading the implementation of np.lib.stride_tricks.as_strided, I found it is a problem with np.asanyarray.

np.asanyarray does have a 'guard' for its argument, if you pass into a DummArray whose interface.shape is bigger than 64 and smaller than 136, it raises a ValueError: number of dimensions must be within [0, 64].

But this 'guard' fails when the size interface.shape is larger than 135, and a Segmentation Fault is achieved.

Reproduce the code example:

import numpy as np

x = 1 # x can be one of [1, [1], 's']
shape = [1]*136 # 0-135 is safe

# np.lib.stride_tricks.as_strided(x, shape=shape)

class DummyArray:
    """Dummy object that just exists to hang __array_interface__ dictionaries
    and possibly keep alive a reference to a base array.
    """

    def __init__(self, interface, base=None):
        self.__array_interface__ = interface
        self.base = base
x = np.array(x, copy=None, subok=False)
interface = dict(x.__array_interface__)
interface['shape'] = tuple(shape)
da = DummyArray(interface=interface, base=x)
np.asanyarray(da)

Error message:

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x0000000000000001 in ?? ()
(gdb) bt
#0  0x0000000000000001 in ?? ()
#1  0x00007ffc81825b7c in ?? ()
#2  0x00007ffc81825b68 in ?? ()
#3  0x00007f12f2ef2780 in ?? ()
#4  0x0000000000000000 in ?? ()

Python and NumPy Versions:

2.2.0
3.12.7 | packaged by Anaconda, Inc. | (main, Oct 4 2024, 13:27:36) [GCC 11.2.0]

Runtime Environment:

[{'numpy_version': '2.2.0',
'python': '3.12.7 | packaged by Anaconda, Inc. | (main, Oct 4 2024, '
'13:27:36) [GCC 11.2.0]',
'uname': uname_result(system='Linux', node='a475b702ecc0', release='5.4.0-150-generic', version='#167~18.04.1-Ubuntu SMP Wed May 24 00:51:42 UTC 2023', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2',
'AVX512F',
'AVX512CD',
'AVX512_SKX',
'AVX512_CLX'],
'not_found': ['AVX512_KNL',
'AVX512_KNM',
'AVX512_CNL',
'AVX512_ICL']}},
{'architecture': 'SkylakeX',
'filepath': '/root/miniconda3/envs/py312/lib/python3.12/site-packages/numpy.libs/libscipy_openblas64_-6bb31eeb.so',
'internal_api': 'openblas',
'num_threads': 64,
'prefix': 'libscipy_openblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.28'}]

Context for the issue:

I thought the boundary check for numpy.asanyarray can be improved.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.