Describe the issue:
Converting anumpy timedelta64 array to strings seems to not check the string length requested. It not only produces truncated output, but also seems to write past the array boundary. Eventually this will then lead to a segmentation fault later.
Reproduce the code example:
import numpy as np
a = np.array([1, -2, 1], dtype='timedelta64[D]')
a.astype('S1')
Error message:
Here's some output from valgrind:
>>> import numpy as np
>>> a = np.array([1, -2, 12, 1], dtype='timedelta64[D]')
>>> a.astype('S1')
==3910678== Invalid write of size 2
==3910678== at 0x4C46173: memmove (vg_replace_strmem.c:1410)
==3910678== by 0x17A42EE6: STRING_setitem (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17A4348B: LONG_to_STRING (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17BAFEE1: _aligned_strided_to_strided_cast (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B6FD53: raw_array_assign_array (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B709BF: PyArray_AssignArray (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17BD3C03: array_astype (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x5048731: method_vectorcall_FASTCALL_KEYWORDS (descrobject.c:426)
==3910678== by 0x50226FB: UnknownInlinedFun (pycore_call.h:92)
==3910678== by 0x50226FB: PyObject_Vectorcall (call.c:299)
==3910678== by 0x5012FF1: _PyEval_EvalFrameDefault (ceval.c:4769)
==3910678== by 0x500EB11: UnknownInlinedFun (pycore_ceval.h:73)
==3910678== by 0x500EB11: _PyEval_Vector (ceval.c:6434)
==3910678== by 0x509D03B: PyEval_EvalCode (ceval.c:1148)
==3910678== Address 0x172e7b64 is 0 bytes after a block of size 4 alloc'd
==3910678== at 0x4C39185: malloc (vg_replace_malloc.c:442)
==3910678== by 0x17B67EDD: PyDataMem_UserNEW (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B89EFF: PyArray_NewFromDescr_int (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B8A16F: PyArray_NewFromDescr (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17CA4737: ufunc_generic_fastcall (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x50226FB: UnknownInlinedFun (pycore_call.h:92)
==3910678== by 0x50226FB: PyObject_Vectorcall (call.c:299)
==3910678== by 0x5012FF1: _PyEval_EvalFrameDefault (ceval.c:4769)
==3910678== by 0x500EB11: UnknownInlinedFun (pycore_ceval.h:73)
==3910678== by 0x500EB11: _PyEval_Vector (ceval.c:6434)
==3910678== by 0x509D03B: PyEval_EvalCode (ceval.c:1148)
==3910678== by 0x50B3965: UnknownInlinedFun (bltinmodule.c:1077)
==3910678== by 0x50B3965: builtin_exec (bltinmodule.c.h:465)
==3910678== by 0x5022799: cfunction_vectorcall_FASTCALL_KEYWORDS (methodobject.c:443)
==3910678== by 0x501BF2E: UnknownInlinedFun (call.c:355)
==3910678== by 0x501BF2E: UnknownInlinedFun (ceval.c:7321)
==3910678== by 0x501BF2E: _PyEval_EvalFrameDefault (ceval.c:5376)
==3910678==
==3910678== Invalid write of size 1
==3910678== at 0x4C45F49: memset (vg_replace_strmem.c:1386)
==3910678== by 0x17A42F3D: STRING_setitem (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17A4348B: LONG_to_STRING (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17BAFEE1: _aligned_strided_to_strided_cast (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B6FD53: raw_array_assign_array (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B709BF: PyArray_AssignArray (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17BD3C03: array_astype (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x5048731: method_vectorcall_FASTCALL_KEYWORDS (descrobject.c:426)
==3910678== by 0x50226FB: UnknownInlinedFun (pycore_call.h:92)
==3910678== by 0x50226FB: PyObject_Vectorcall (call.c:299)
==3910678== by 0x5012FF1: _PyEval_EvalFrameDefault (ceval.c:4769)
==3910678== by 0x500EB11: UnknownInlinedFun (pycore_ceval.h:73)
==3910678== by 0x500EB11: _PyEval_Vector (ceval.c:6434)
==3910678== by 0x509D03B: PyEval_EvalCode (ceval.c:1148)
==3910678== Address 0x172e7b66 is 2 bytes after a block of size 4 alloc'd
==3910678== at 0x4C39185: malloc (vg_replace_malloc.c:442)
==3910678== by 0x17B67EDD: PyDataMem_UserNEW (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B89EFF: PyArray_NewFromDescr_int (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B8A16F: PyArray_NewFromDescr (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17CA4737: ufunc_generic_fastcall (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x50226FB: UnknownInlinedFun (pycore_call.h:92)
==3910678== by 0x50226FB: PyObject_Vectorcall (call.c:299)
==3910678== by 0x5012FF1: _PyEval_EvalFrameDefault (ceval.c:4769)
==3910678== by 0x500EB11: UnknownInlinedFun (pycore_ceval.h:73)
==3910678== by 0x500EB11: _PyEval_Vector (ceval.c:6434)
==3910678== by 0x509D03B: PyEval_EvalCode (ceval.c:1148)
==3910678== by 0x50B3965: UnknownInlinedFun (bltinmodule.c:1077)
==3910678== by 0x50B3965: builtin_exec (bltinmodule.c.h:465)
==3910678== by 0x5022799: cfunction_vectorcall_FASTCALL_KEYWORDS (methodobject.c:443)
==3910678== by 0x501BF2E: UnknownInlinedFun (call.c:355)
==3910678== by 0x501BF2E: UnknownInlinedFun (ceval.c:7321)
==3910678== by 0x501BF2E: _PyEval_EvalFrameDefault (ceval.c:5376)
==3910678==
==3910678== Invalid write of size 8
==3910678== at 0x4C45FD4: memset (vg_replace_strmem.c:1386)
==3910678== by 0x17A42F3D: STRING_setitem (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17A4348B: LONG_to_STRING (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17BAFEE1: _aligned_strided_to_strided_cast (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B6FD53: raw_array_assign_array (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B709BF: PyArray_AssignArray (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17BD3C03: array_astype (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x5048731: method_vectorcall_FASTCALL_KEYWORDS (descrobject.c:426)
==3910678== by 0x50226FB: UnknownInlinedFun (pycore_call.h:92)
==3910678== by 0x50226FB: PyObject_Vectorcall (call.c:299)
==3910678== by 0x5012FF1: _PyEval_EvalFrameDefault (ceval.c:4769)
==3910678== by 0x500EB11: UnknownInlinedFun (pycore_ceval.h:73)
==3910678== by 0x500EB11: _PyEval_Vector (ceval.c:6434)
==3910678== by 0x509D03B: PyEval_EvalCode (ceval.c:1148)
==3910678== Address 0x172e7b68 is 4 bytes after a block of size 4 alloc'd
==3910678== at 0x4C39185: malloc (vg_replace_malloc.c:442)
==3910678== by 0x17B67EDD: PyDataMem_UserNEW (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B89EFF: PyArray_NewFromDescr_int (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B8A16F: PyArray_NewFromDescr (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17CA4737: ufunc_generic_fastcall (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x50226FB: UnknownInlinedFun (pycore_call.h:92)
==3910678== by 0x50226FB: PyObject_Vectorcall (call.c:299)
==3910678== by 0x5012FF1: _PyEval_EvalFrameDefault (ceval.c:4769)
==3910678== by 0x500EB11: UnknownInlinedFun (pycore_ceval.h:73)
==3910678== by 0x500EB11: _PyEval_Vector (ceval.c:6434)
==3910678== by 0x509D03B: PyEval_EvalCode (ceval.c:1148)
==3910678== by 0x50B3965: UnknownInlinedFun (bltinmodule.c:1077)
==3910678== by 0x50B3965: builtin_exec (bltinmodule.c.h:465)
==3910678== by 0x5022799: cfunction_vectorcall_FASTCALL_KEYWORDS (methodobject.c:443)
==3910678== by 0x501BF2E: UnknownInlinedFun (call.c:355)
==3910678== by 0x501BF2E: UnknownInlinedFun (ceval.c:7321)
==3910678== by 0x501BF2E: _PyEval_EvalFrameDefault (ceval.c:5376)
==3910678==
==3910678== Invalid write of size 1
==3910678== at 0x4C46010: memset (vg_replace_strmem.c:1386)
==3910678== by 0x17A42F3D: STRING_setitem (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17A4348B: LONG_to_STRING (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17BAFEE1: _aligned_strided_to_strided_cast (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B6FD53: raw_array_assign_array (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B709BF: PyArray_AssignArray (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17BD3C03: array_astype (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x5048731: method_vectorcall_FASTCALL_KEYWORDS (descrobject.c:426)
==3910678== by 0x50226FB: UnknownInlinedFun (pycore_call.h:92)
==3910678== by 0x50226FB: PyObject_Vectorcall (call.c:299)
==3910678== by 0x5012FF1: _PyEval_EvalFrameDefault (ceval.c:4769)
==3910678== by 0x500EB11: UnknownInlinedFun (pycore_ceval.h:73)
==3910678== by 0x500EB11: _PyEval_Vector (ceval.c:6434)
==3910678== by 0x509D03B: PyEval_EvalCode (ceval.c:1148)
==3910678== Address 0x172e7b70 is 12 bytes after a block of size 4 alloc'd
==3910678== at 0x4C39185: malloc (vg_replace_malloc.c:442)
==3910678== by 0x17B67EDD: PyDataMem_UserNEW (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B89EFF: PyArray_NewFromDescr_int (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B8A16F: PyArray_NewFromDescr (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17CA4737: ufunc_generic_fastcall (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x50226FB: UnknownInlinedFun (pycore_call.h:92)
==3910678== by 0x50226FB: PyObject_Vectorcall (call.c:299)
==3910678== by 0x5012FF1: _PyEval_EvalFrameDefault (ceval.c:4769)
==3910678== by 0x500EB11: UnknownInlinedFun (pycore_ceval.h:73)
==3910678== by 0x500EB11: _PyEval_Vector (ceval.c:6434)
==3910678== by 0x509D03B: PyEval_EvalCode (ceval.c:1148)
==3910678== by 0x50B3965: UnknownInlinedFun (bltinmodule.c:1077)
==3910678== by 0x50B3965: builtin_exec (bltinmodule.c.h:465)
==3910678== by 0x5022799: cfunction_vectorcall_FASTCALL_KEYWORDS (methodobject.c:443)
==3910678== by 0x501BF2E: UnknownInlinedFun (call.c:355)
==3910678== by 0x501BF2E: UnknownInlinedFun (ceval.c:7321)
==3910678== by 0x501BF2E: _PyEval_EvalFrameDefault (ceval.c:5376)
==3910678==
==3910678== Invalid write of size 1
==3910678== at 0x4C4601A: memset (vg_replace_strmem.c:1386)
==3910678== by 0x17A42F3D: STRING_setitem (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17A4348B: LONG_to_STRING (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17BAFEE1: _aligned_strided_to_strided_cast (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B6FD53: raw_array_assign_array (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B709BF: PyArray_AssignArray (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17BD3C03: array_astype (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x5048731: method_vectorcall_FASTCALL_KEYWORDS (descrobject.c:426)
==3910678== by 0x50226FB: UnknownInlinedFun (pycore_call.h:92)
==3910678== by 0x50226FB: PyObject_Vectorcall (call.c:299)
==3910678== by 0x5012FF1: _PyEval_EvalFrameDefault (ceval.c:4769)
==3910678== by 0x500EB11: UnknownInlinedFun (pycore_ceval.h:73)
==3910678== by 0x500EB11: _PyEval_Vector (ceval.c:6434)
==3910678== by 0x509D03B: PyEval_EvalCode (ceval.c:1148)
==3910678== Address 0x172e7b72 is 14 bytes after a block of size 4 alloc'd
==3910678== at 0x4C39185: malloc (vg_replace_malloc.c:442)
==3910678== by 0x17B67EDD: PyDataMem_UserNEW (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B89EFF: PyArray_NewFromDescr_int (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B8A16F: PyArray_NewFromDescr (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17CA4737: ufunc_generic_fastcall (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x50226FB: UnknownInlinedFun (pycore_call.h:92)
==3910678== by 0x50226FB: PyObject_Vectorcall (call.c:299)
==3910678== by 0x5012FF1: _PyEval_EvalFrameDefault (ceval.c:4769)
==3910678== by 0x500EB11: UnknownInlinedFun (pycore_ceval.h:73)
==3910678== by 0x500EB11: _PyEval_Vector (ceval.c:6434)
==3910678== by 0x509D03B: PyEval_EvalCode (ceval.c:1148)
==3910678== by 0x50B3965: UnknownInlinedFun (bltinmodule.c:1077)
==3910678== by 0x50B3965: builtin_exec (bltinmodule.c.h:465)
==3910678== by 0x5022799: cfunction_vectorcall_FASTCALL_KEYWORDS (methodobject.c:443)
==3910678== by 0x501BF2E: UnknownInlinedFun (call.c:355)
==3910678== by 0x501BF2E: UnknownInlinedFun (ceval.c:7321)
==3910678== by 0x501BF2E: _PyEval_EvalFrameDefault (ceval.c:5376)
==3910678==
==3910678== Invalid write of size 1
==3910678== at 0x4C461A4: memmove (vg_replace_strmem.c:1410)
==3910678== by 0x17A42EE6: STRING_setitem (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17A4348B: LONG_to_STRING (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17BAFEE1: _aligned_strided_to_strided_cast (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B6FD53: raw_array_assign_array (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B709BF: PyArray_AssignArray (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17BD3C03: array_astype (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x5048731: method_vectorcall_FASTCALL_KEYWORDS (descrobject.c:426)
==3910678== by 0x50226FB: UnknownInlinedFun (pycore_call.h:92)
==3910678== by 0x50226FB: PyObject_Vectorcall (call.c:299)
==3910678== by 0x5012FF1: _PyEval_EvalFrameDefault (ceval.c:4769)
==3910678== by 0x500EB11: UnknownInlinedFun (pycore_ceval.h:73)
==3910678== by 0x500EB11: _PyEval_Vector (ceval.c:6434)
==3910678== by 0x509D03B: PyEval_EvalCode (ceval.c:1148)
==3910678== Address 0x172e7b64 is 0 bytes after a block of size 4 alloc'd
==3910678== at 0x4C39185: malloc (vg_replace_malloc.c:442)
==3910678== by 0x17B67EDD: PyDataMem_UserNEW (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B89EFF: PyArray_NewFromDescr_int (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17B8A16F: PyArray_NewFromDescr (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x17CA4737: ufunc_generic_fastcall (in /prod/pyinf/python-3.11-numpy-2.4/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so)
==3910678== by 0x50226FB: UnknownInlinedFun (pycore_call.h:92)
==3910678== by 0x50226FB: PyObject_Vectorcall (call.c:299)
==3910678== by 0x5012FF1: _PyEval_EvalFrameDefault (ceval.c:4769)
==3910678== by 0x500EB11: UnknownInlinedFun (pycore_ceval.h:73)
==3910678== by 0x500EB11: _PyEval_Vector (ceval.c:6434)
==3910678== by 0x509D03B: PyEval_EvalCode (ceval.c:1148)
==3910678== by 0x50B3965: UnknownInlinedFun (bltinmodule.c:1077)
==3910678== by 0x50B3965: builtin_exec (bltinmodule.c.h:465)
==3910678== by 0x5022799: cfunction_vectorcall_FASTCALL_KEYWORDS (methodobject.c:443)
==3910678== by 0x501BF2E: UnknownInlinedFun (call.c:355)
==3910678== by 0x501BF2E: UnknownInlinedFun (ceval.c:7321)
==3910678== by 0x501BF2E: _PyEval_EvalFrameDefault (ceval.c:5376)
==3910678==
array([b'1', b'-', b'1', b'1'], dtype='|S1')
Python and NumPy Versions:
2.4.1
3.11.13 (main, Aug 1 2025, 03:38:54) [GCC 10.3.1 20210422 (Red Hat 10.3.1-1)]
Runtime Environment:
[{'numpy_version': '2.4.1',
'python': '3.11.13 (main, Aug 1 2025, 03:38:54) [GCC 10.3.1 20210422 (Red '
'Hat 10.3.1-1)]',
'uname': uname_result(system='Linux', node='redacted', release='4.18.0-553.97.1.el8_10.x86_64', version='#1 SMP Tue Jan 20 00:58:00 EST 2026', machine='x86_64')},
{'simd_extensions': {'baseline': ['X86_V2'],
'found': ['X86_V3', 'X86_V4'],
'not_found': ['AVX512_ICL', 'AVX512_SPR']}},
{'ignore_floating_point_errors_in_matmul': False},
{'filepath': '/usr/lib64/libmkl_rt.so.2',
'internal_api': 'mkl',
'num_threads': None,
'prefix': 'libmkl_rt',
'threading_layer': 'not specified',
'user_api': 'blas',
'version': None},
{'filepath': '/opt/intel/oneapi/mkl/2025.3/lib/libmkl_rt.so.2',
'internal_api': 'mkl',
'num_threads': 1,
'prefix': 'libmkl_rt',
'threading_layer': 'gnu',
'user_api': 'blas',
'version': '2025.3-Product'},
{'filepath': '/usr/lib64/libgomp.so.1.0.0',
'internal_api': 'openmp',
'num_threads': 20,
'prefix': 'libgomp',
'user_api': 'openmp',
'version': None}]
How does this issue affect you or how did you find it:
Random process crashes if the string size is chosen as too small for successful conversion.
Even if the strings were not writing out-of-bounds it still produces truncated output.
Describe the issue:
Converting anumpy timedelta64 array to strings seems to not check the string length requested. It not only produces truncated output, but also seems to write past the array boundary. Eventually this will then lead to a segmentation fault later.
Reproduce the code example:
Error message:
Python and NumPy Versions:
2.4.1
3.11.13 (main, Aug 1 2025, 03:38:54) [GCC 10.3.1 20210422 (Red Hat 10.3.1-1)]
Runtime Environment:
[{'numpy_version': '2.4.1',
'python': '3.11.13 (main, Aug 1 2025, 03:38:54) [GCC 10.3.1 20210422 (Red '
'Hat 10.3.1-1)]',
'uname': uname_result(system='Linux', node='redacted', release='4.18.0-553.97.1.el8_10.x86_64', version='#1 SMP Tue Jan 20 00:58:00 EST 2026', machine='x86_64')},
{'simd_extensions': {'baseline': ['X86_V2'],
'found': ['X86_V3', 'X86_V4'],
'not_found': ['AVX512_ICL', 'AVX512_SPR']}},
{'ignore_floating_point_errors_in_matmul': False},
{'filepath': '/usr/lib64/libmkl_rt.so.2',
'internal_api': 'mkl',
'num_threads': None,
'prefix': 'libmkl_rt',
'threading_layer': 'not specified',
'user_api': 'blas',
'version': None},
{'filepath': '/opt/intel/oneapi/mkl/2025.3/lib/libmkl_rt.so.2',
'internal_api': 'mkl',
'num_threads': 1,
'prefix': 'libmkl_rt',
'threading_layer': 'gnu',
'user_api': 'blas',
'version': '2025.3-Product'},
{'filepath': '/usr/lib64/libgomp.so.1.0.0',
'internal_api': 'openmp',
'num_threads': 20,
'prefix': 'libgomp',
'user_api': 'openmp',
'version': None}]
How does this issue affect you or how did you find it:
Random process crashes if the string size is chosen as too small for successful conversion.
Even if the strings were not writing out-of-bounds it still produces truncated output.