b10-msgpack-numpy 0.4.8__tar.gz → 0.4.8.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,16 @@ vi:ft=markdown
5
5
  Change Log
6
6
  ==========
7
7
 
8
+ Release 0.4.8.1 (Baseten fork, November 2026)
9
+ ---------------------------------------------
10
+ * SECURITY: ``decode`` now raises ``ValueError`` for an ndarray payload whose
11
+ dtype holds Python objects under any kind other than ``O`` (for example
12
+ ``type: "|O"`` with ``kind: "f"``, or a structured dtype with an object
13
+ field). These built the array directly over the payload bytes and read
14
+ them as object pointers, which crashes the process. Structured arrays with
15
+ object fields can no longer be round-tripped; their encoded bytes were
16
+ only valid within the encoding process.
17
+
8
18
  Release 0.4.8 (Baseten fork, November 2026)
9
19
  -------------------------------------------
10
20
  * SECURITY (CWE-502): object-dtype ndarrays are no longer unpickled by
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: b10-msgpack-numpy
3
- Version: 0.4.8
3
+ Version: 0.4.8.1
4
4
  Summary: Numpy data serialization using msgpack (Baseten fork with CWE-502 fix)
5
5
  Home-page: https://github.com/basetenlabs/b10-msgpack-numpy
6
6
  Author: Lev E. Givon
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: b10-msgpack-numpy
3
- Version: 0.4.8
3
+ Version: 0.4.8.1
4
4
  Summary: Numpy data serialization using msgpack (Baseten fork with CWE-502 fix)
5
5
  Home-page: https://github.com/basetenlabs/b10-msgpack-numpy
6
6
  Author: Lev E. Givon
@@ -125,8 +125,16 @@ def decode(obj, chain=None, allow_pickle=False):
125
125
  return pickle.loads(obj[b'data'])
126
126
  else:
127
127
  descr = obj[b'type']
128
+
129
+ # Object fields in a raw buffer would be read as object
130
+ # pointers. np.frombuffer refuses this; np.ndarray does not.
131
+ dtype = _unpack_dtype(descr)
132
+ if dtype.hasobject:
133
+ raise ValueError(
134
+ 'cannot create an OBJECT array from memory buffer')
135
+
128
136
  return np.ndarray(buffer=obj[b'data'],
129
- dtype=_unpack_dtype(descr),
137
+ dtype=dtype,
130
138
  shape=obj[b'shape'])
131
139
  else:
132
140
  descr = obj[b'type']
@@ -6,7 +6,7 @@ import re
6
6
  from setuptools import setup
7
7
 
8
8
  NAME = 'b10-msgpack-numpy'
9
- VERSION = '0.4.8'
9
+ VERSION = '0.4.8.1'
10
10
  AUTHOR = 'Lev E. Givon'
11
11
  AUTHOR_EMAIL = 'lev@columbia.edu'
12
12
  URL = 'https://github.com/basetenlabs/b10-msgpack-numpy'
@@ -238,6 +238,36 @@ class test_numpy_msgpack(TestCase):
238
238
  msgpack.unpackb(payload, allow_pickle=True)
239
239
  self.assertEqual(EXECUTED, [True])
240
240
 
241
+ def test_object_dtype_raw_buffer_rejected(self):
242
+ # Hostile payloads naming an object dtype under a kind other than
243
+ # "O", which would read the raw data bytes as object pointers.
244
+ types_by_kind = [
245
+ (b'f', b'|O'),
246
+ (None, b'|O'),
247
+ (b'', 'object'),
248
+ (b'', 'O8'),
249
+ (b'', '(2,)O'),
250
+ (b'V', [(b'a', b'|O')]),
251
+ (b'V', [(b'a', [('b', '|O')])]),
252
+ (b'', 'i4,O'),
253
+ ]
254
+ for kind, dtype_type in types_by_kind:
255
+ obj = {b'nd': True, b'type': dtype_type, b'shape': (2,),
256
+ b'data': b'\x41' * 64}
257
+ if kind is not None:
258
+ obj[b'kind'] = kind
259
+ payload = msgpack.packb(obj)
260
+ for allow_pickle in (False, True):
261
+ with self.assertRaisesRegex(ValueError, 'OBJECT array'):
262
+ msgpack.unpackb(payload, allow_pickle=allow_pickle)
263
+
264
+ def test_structured_array_with_object_field_rejected(self):
265
+ # The encoder writes these as raw object pointers, so they can't be
266
+ # decoded safely.
267
+ x = np.array([(1, 'a')], dtype=[('n', '<i4'), ('o', 'O')])
268
+ with self.assertRaisesRegex(ValueError, 'OBJECT array'):
269
+ msgpack.unpackb(msgpack.packb(x))
270
+
241
271
  def test_numpy_array_complex(self):
242
272
  x = (np.random.rand(5)+1j*np.random.rand(5)).astype(np.complex128)
243
273
  x_rec = self.encode_decode(x)