Skip to content

BUG: np.fill_diagonal with StringDType and large integer input causes segmentation fault #29659

@Kairoven

Description

@Kairoven

Describe the issue:

When using np.fill_diagonal on a StringDType array, passing in a large integer value causes a segmentation fault instead of raising a Python exception.

Reproduce the code example:

import numpy as np
from numpy.dtypes import StringDType

# Example 1: works
m_array = np.array([['0', 'ti'], ['re', '0']], dtype=StringDType)
np.fill_diagonal(m_array, 'do')
print(repr(m_array))
# array([['do', 'ti'],
#        ['re', 'do']], dtype=StringDType())

# Example 2: works (integer is converted to string)
m_array = np.array([['0', 'ti'], ['re', '0']], dtype=StringDType)
np.fill_diagonal(m_array, 92)
print(repr(m_array))
# array([['92', 'ti'],
#        ['re', '92']], dtype=StringDType())

# Example 3: crashes with segmentation fault
m_array = np.array([['0', 'ti'], ['re', '0']], dtype=StringDType)
np.fill_diagonal(m_array, 9223372036854775)  # very large integer
print(repr(m_array))  
# Segmentation fault (core dumped)

Error message:

Segmentation fault (core dumped)

Python and NumPy Versions:

2.2.6
3.12.0 | packaged by Anaconda, Inc. | (main, Oct 2 2023, 17:29:18) [GCC 11.2.0]
or
2.3.2
3.11.13 (main, Jun 5 2025, 13:12:00) [GCC 11.2.0]

Runtime Environment:

[{'numpy_version': '2.2.6',
'python': '3.12.0 | packaged by Anaconda, Inc. | (main, Oct 2 2023, '
'17:29:18) [GCC 11.2.0]',
'uname': uname_result(system='Linux', node='gpu-node10', release='5.4.0-100-generic', version='#113-Ubuntu SMP Thu Feb 3 18:43:29 UTC 2022', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2',
'AVX512F',
'AVX512CD',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL'],
'not_found': ['AVX512_KNL', 'AVX512_KNM']}},
{'architecture': 'SkylakeX',
'filepath': '/home/xxx/lib/python3.12/site-packages/numpy.libs/libscipy_openblas64_-56d6093b.so',
'internal_api': 'openblas',
'num_threads': 64,
'prefix': 'libscipy_openblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.29'}]

Context for the issue:

Expected behavior:

For large integer inputs, the value should either:

  • be safely converted to a string (same as smaller integers), or

  • raise a ValueError or OverflowError if the conversion cannot be handled.

Actual behavior:
The interpreter crashes with a segmentation fault.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions