File tree Expand file tree Collapse file tree 3 files changed +17
-0
lines changed Expand file tree Collapse file tree 3 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ Release notes
44
55* Drop support for 32-bit Windows. By :user: `Alistair Miles <alimanfoo> `, :issue: `97 `, :issue: `156 `.
66
7+ * Raise a ``TypeError `` if an ``object `` array is passed to ``ensure_bytes ``.
8+ By :user: `John Kirkham <jakirkham> `, :issue: `162 `.
9+
710
811.. _release_0.6.2 :
912
Original file line number Diff line number Diff line change @@ -152,6 +152,11 @@ def ensure_bytes(buf):
152152 # go via numpy, for convenience
153153 arr = ensure_ndarray (buf )
154154
155+ # check for object arrays, these are just memory pointers,
156+ # actual memory holding item data is scattered elsewhere
157+ if arr .dtype == object :
158+ raise TypeError ('object arrays are not supported' )
159+
155160 # create bytes
156161 buf = arr .tobytes (order = 'A' )
157162
Original file line number Diff line number Diff line change @@ -51,6 +51,15 @@ def test_ensure_contiguous_ndarray_shares_memory():
5151 assert np .shares_memory (a , memoryview (buf ))
5252
5353
54+ def test_ensure_bytes_invalid_inputs ():
55+
56+ # object array not allowed
57+ a = np .array ([u'Xin chào thế giới' ], dtype = object )
58+ for e in [a , memoryview (a )]:
59+ with pytest .raises (TypeError ):
60+ ensure_bytes (e )
61+
62+
5463def test_ensure_contiguous_ndarray_invalid_inputs ():
5564
5665 # object array not allowed
You can’t perform that action at this time.
0 commit comments