Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible to fail to calc mro's #36539

Closed
mwhudson opened this issue May 2, 2002 · 8 comments
Closed

possible to fail to calc mro's #36539

mwhudson opened this issue May 2, 2002 · 8 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@mwhudson
Copy link

mwhudson commented May 2, 2002

BPO 551412
Nosy @mwhudson, @gvanrossum

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/gvanrossum'
closed_at = <Date 2002-06-10.14:35:23.000>
created_at = <Date 2002-05-02.13:42:26.000>
labels = ['interpreter-core']
title = "possible to fail to calc mro's"
updated_at = <Date 2002-06-10.14:35:23.000>
user = 'https://github.com/mwhudson'

bugs.python.org fields:

activity = <Date 2002-06-10.14:35:23.000>
actor = 'gvanrossum'
assignee = 'gvanrossum'
closed = True
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2002-05-02.13:42:26.000>
creator = 'mwh'
dependencies = []
files = []
hgrepos = []
issue_num = 551412
keywords = []
message_count = 8.0
messages = ['10633', '10634', '10635', '10636', '10637', '10638', '10639', '10640']
nosy_count = 2.0
nosy_names = ['mwh', 'gvanrossum']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue551412'
versions = ['Python 2.3']

@mwhudson
Copy link
Author

mwhudson commented May 2, 2002

This only crashes on the release22-maint branch, and
only when coredump is true:

class UserLong(object):
    def __pow__(self, *args):
        pass

coredump = 1

if not coredump:
   int.__mro__

pow(0, UserLong(), 0)

It's the type of the first argument to pow() that's
relavent: if you change it to "pow(0L, UserLong(), 0)"
you then have to change "int.__mro__" to "long.__mro__"
to avoid the crash.

Maybe it was the "typeobject.c refactoring" patch that
accidentally fixed this on the trunk?

@mwhudson mwhudson closed this as completed May 2, 2002
@mwhudson mwhudson added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label May 2, 2002
@mwhudson mwhudson closed this as completed May 2, 2002
@mwhudson mwhudson added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label May 2, 2002
@gvanrossum
Copy link
Member

Logged In: YES
user_id=6380

Hm, this is serious.

This can happen whenever a built-in type
isn't initialized by PyType_Ready() yet,
and for many that is pretty common.
(The call to int.__mro__ goes through
type_getattro which calls PyType_Ready().)

I'm not sure which refactoring patch
you are referring to, and I'm actually
not at all sure that this can't happen
in 2.3 (despite the fact that this
particular example doesn't core dump there).

I'll investigate more...

@gvanrossum
Copy link
Member

Logged In: YES
user_id=6380

In fact, this still crashes in 2.2:
pow(0L, UserLong(), 0L)

@gvanrossum
Copy link
Member

Logged In: YES
user_id=6380

OK, I nailed it.

The fix is to call PyType_Ready()
in _PyType_Lookup() when mro is NULL.

Fixed in both 2.3 and 2.2.
A test case added only for 2.3.

@gvanrossum
Copy link
Member

Logged In: YES
user_id=6380

Argh, reopening.

There's one little detail left:
_PyType_Lookup() promises not
to set an exception. If the call
to PyType_Ready() fails, this
promise is broken...

What to do? PyErr_Clear()
and return NULL comes to mind...

@gvanrossum
Copy link
Member

Logged In: YES
user_id=6380

OK, fixed that too in 2.2.x and in 2.3, by calling
PyErr_Clear(). Not ideal, but not bad either.

@gvanrossum
Copy link
Member

Logged In: YES
user_id=6380

I'm reopening this (as a reminder to myself). Calling
PyType_Ready() from _PyType_Lookup() is fishy. It may be
that the real problem is in slot_nb_power(), which tries to
call self.__pow__(other, modulus) without checking that
self...nb_power is inseed slot_nb_power.

@gvanrossum
Copy link
Member

Logged In: YES
user_id=6380

Fixed again, this time properly (I hope :-).

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Development

No branches or pull requests

2 participants