Skip to content

Commit 6474dae

Browse files
committed
Address review feedback: harden numpy_parser and improve tests
- Add buffer size guard before memcpy in unpack_row() to prevent overflow - Remove dead mask_true constant and unused uint8_t cimport - Fix copyright header (DataStax -> ScyllaDB) - Replace hard-coded little-endian dtypes with native numpy dtypes - Remove unused Mock import - Add test for NULL vector mask handling - Add test for unsupported subtype fallback to object array
1 parent d9dfe9e commit 6474dae

2 files changed

Lines changed: 169 additions & 110 deletions

File tree

cassandra/numpy_parser.pyx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ as numpy is an optional dependency.
2525
include "ioutils.pyx"
2626

2727
cimport cython
28-
from libc.stdint cimport uint64_t, uint8_t
28+
from libc.stdint cimport uint64_t
2929
from libc.string cimport memset
3030
from cpython.ref cimport Py_INCREF, PyObject
3131

@@ -74,8 +74,6 @@ _cqltype_to_numpy = {
7474

7575
obj_dtype = np.dtype('O')
7676

77-
cdef uint8_t mask_true = 0x01
78-
7977
cdef class NumpyParser(ColumnParser):
8078
"""Decode a ResultMessage into a bunch of NumPy arrays"""
8179

@@ -181,6 +179,10 @@ cdef inline int unpack_row(
181179
Py_INCREF(val)
182180
(<PyObject **> arr.buf_ptr)[0] = <PyObject *> val
183181
elif buf.size >= 0:
182+
if buf.size > arr.stride:
183+
raise ValueError(
184+
"Column %d: received %d bytes but array stride is %d" %
185+
(i, buf.size, arr.stride))
184186
memcpy(<char *> arr.buf_ptr, buf.ptr, buf.size)
185187
else:
186188
memset(<char *>arr.mask_ptr, 1, arr.mask_stride)

0 commit comments

Comments
 (0)