Skip to content

Conversation

@charris
Copy link
Member

@charris charris commented Oct 23, 2025

If the slice start > stop, then slice_strided_loop() attempts to allocate a string of negative size, causing a MemoryError. To replicate:

>>> a = np.array(['test-strings'], dtype="T")
>>> np.strings.slice(a, 6, 5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lib/python3.12/site-packages/numpy/_core/strings.py", line 1813, in slice
    return _slice(a, start, stop, step)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
MemoryError: Failed to allocate string in slice

If the slice start > stop, then `slice_strided_loop()` attempts to
allocate a string of negative size, causing a MemoryError. To replicate:
```
>>> a = np.array(['test-strings'], dtype="T")
>>> np.strings.slice(a, 6, 5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lib/python3.12/site-packages/numpy/_core/strings.py", line 1813, in slice
    return _slice(a, start, stop, step)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
MemoryError: Failed to allocate string in slice
```
@charris charris added this to the 2.3.5 release milestone Oct 23, 2025
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Oct 23, 2025
@charris charris merged commit d2980e4 into numpy:maintenance/2.3.x Oct 23, 2025
75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 08 - Backport Used to tag backport PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants