[Python-bugs-list] [ python-Bugs-446049 ] file type is callable but crashes
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 02 Aug 2001 08:02:45 -0700
Bugs item #446049, was opened at 2001-07-30 11:51
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=446049&group_id=5470
Category: type/class unification
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Gregory H. Ball (greg_ball)
Assigned to: Guido van Rossum (gvanrossum)
Summary: file type is callable but crashes
Initial Comment:
Calling the type of a file object results
in a crash. More details to follow.
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-02 08:02
Message:
Logged In: YES
user_id=6380
The direct cause is that the tp_new slot inherited from
'object' creates a file object that is initialized to all
zeros, and the file object's tp_repr slot doesn't anticipate
that.
I can fix the file object in a number of ways (make it work
for uninitialized objects, or add a tp_new slot that
initializes it properly). But I expect that file is not the
only type that is vulnerable to this kind of attack,
especially 3rd party types that adopt
PyObject_GenericGetAttr() but don't define their own tp_new
are vulnerable.
The alternative would be to remove the default tp_new
implementation from 'object', and add one to dynamically
created types. That would mean you couldn't call object() to
get a featureless object, which is currently supported and
even tested in test_descr.py.
Any preferences?
----------------------------------------------------------------------
Comment By: Gregory H. Ball (greg_ball)
Date: 2001-07-30 11:57
Message:
Logged In: YES
user_id=11365
Python 2.2a1 (#2, Jul 26 2001, 11:50:01)
[GCC 2.95.3 19991030 (prerelease)] on linux2
Type "copyright", "credits" or "license" for more
information.
>>> f = open('README')
>>> type(f)()
Segmentation fault (core dumped)
Seems to me that it would be nice if FileType
worked like the 'open' builtin.
You could have a 'file' builtin and alias it to open.
Wild speculation: I guess open could be eventually
deprecated. At which point you could safely do
from os import * ;-)
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=446049&group_id=5470