This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: buffer() can point to freed memory
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: nascheme Nosy List: lpd, nascheme
Priority: normal Keywords:

Created on 2004-05-08 04:02 by lpd, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg20741 - (view) Author: L. Peter Deutsch (lpd) Date: 2004-05-08 04:02
This is related to the issue in bug 216405, but
different enough that I think it needs consideration.

Sample code:

import array
t = array.array('b', 100 * 'x')
u = buffer(t, 0, 100)
del t[:]
print u[:]

You'll probably get something that is *not* 100 x's,
because the buffer will point to (partly) deallocated
storage.

This problem can arise with any buffer if the object it
references can change length.  Buffers currently refuse
to reference lists, but they don't refuse arrays.

Frankly, I don't know what to recommend here. I was
surprised when I found out that arrays can change
length: my first suggestion is to remove this
capability. If this isn't acceptable, I don't know what
to suggest next.
msg20742 - (view) Author: Neil Schemenauer (nascheme) * (Python committer) Date: 2004-05-08 16:58
Logged In: YES 
user_id=35752

This problem has been fixed in the CVS version of Python for
a while now.  buffer objects no longer store pointers to
memory but use the buffer API to get fresh ones whenever
they are needed.
History
Date User Action Args
2022-04-11 14:56:04adminsetgithub: 40234
2004-05-08 04:02:29lpdcreate