[Python-bugs-list] [ python-Bugs-466752 ] "deref" error in _PyBuffer_FromObject

noreply@sourceforge.net noreply@sourceforge.net
Mon, 01 Oct 2001 01:10:18 -0700


Bugs item #466752, was opened at 2001-10-01 01:10
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=466752&group_id=5470

Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: "deref" error in _PyBuffer_FromObject

Initial Comment:
The "deref" code in function _PyBuffer_FromObject, file
bufferobject.c is an error:
==============
        /* if the base object is another buffer, then
"deref" it */
	if ( PyBuffer_Check(base) )
		base = ((PyBufferObject*)base)->b_base;

	return _PyBuffer_FromMemory(base, (char *)p + offset,
size, readonly);
==============
It is possible, that "deref"'ed base is NULL.
In this case the new object will have no reference to
any base object.

Example (in C):
================
base_buffer=PyBuffer_New(100);
derived_buffer=PyBuffer_FromObject(base_buffer,0,50);
Py_DECREF(base_buffer);
================
And derived_buffer memory pointer points to nowhere.

I think, the right code in _PyBuffer_FromObject would
be:
==============
        /* if the base object is another buffer, then
"deref" it */
	if ( PyBuffer_Check(base) && 
             (((PyBufferObject*)base)->b_base != NULL))
		base = ((PyBufferObject*)base)->b_base;

	return _PyBuffer_FromMemory(base, (char *)p + offset,
size, readonly);
==============

Victor Sologoubov
VSologoubov@ibs.ru


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=466752&group_id=5470