[Numpy-discussion] Deserialized arrays with base mutate strings
Wed Sep 23 03:01:11 CDT 2009
Pauli Virtanen wrote:
> Wed, 23 Sep 2009 09:15:44 +0200, Hrvoje Niksic wrote:
>> Numpy arrays with the "base" property are deserialized as arrays
>> pointing to a storage contained within a Python string. This is a
>> problem since such arrays are mutable and can mutate existing strings.
>> Here is how to create one:
> Please file a bug ticket in the Trac, thanks!
Done - ticket #1233.
> Here is a simpler way, although one more difficult to accidentally:
>>>> a = numpy.frombuffer("A", dtype='S1')
>>>> a.flags.writeable = True
>>>> b = "A"
>>>> a = "B"
I guess this one could be prevented by verifying that the buffer is
writable when setting the "writable" flag. When deserializing arrays, I
don't see a reason for the "base" property to even exist - sharing of
the buffer between different views is unpreserved anyway, as reported in
my other thread.
More information about the NumPy-Discussion