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

The lltrace feature can trigger infinite recursion via __repr__ #107758

Closed
gvanrossum opened this issue Aug 8, 2023 · 0 comments
Closed

The lltrace feature can trigger infinite recursion via __repr__ #107758

gvanrossum opened this issue Aug 8, 2023 · 0 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@gvanrossum
Copy link
Member

gvanrossum commented Aug 8, 2023

When turning on the low-level interpreter tracing feature (lltrace in ceval.c) it is quite easy to hit infinite recursion in dump_stack(), when an item on the stack being printed has a __repr__ method implemented in Python. (This is especially annoying when hardcodinglltrace = 1, since it will never get through the importlib bootstrap -- for some reason the __repr__ for module objects is (re-)implemented in Python.)

While I suppose we could fix this by adding some kind of protection against recursive calls to dump_stack(), I think it's better to just avoid calling into Python at all by writing most objects in the form <type at address> (with exceptions for ints etc.).

CC @sweeneyde, author of dump_stack() in gh-91463. (I don't want to just remove it -- it actually saved my bacon today.)

Linked PRs

@gvanrossum gvanrossum added the type-bug An unexpected behavior, bug, or error label Aug 8, 2023
gvanrossum added a commit that referenced this issue Aug 8, 2023
- The `dump_stack()` method could call a `__repr__` method implemented in Python,
  causing (infinite) recursion.
  I rewrote it to only print out the values for some fundamental types (`int`, `str`, etc.);
  for everything else it just prints `<type_name @ 0xdeadbeef>`.

- The lltrace-like feature for uops wrote to `stderr`, while the one in `ceval.c` writes to `stdout`;
  I changed the uops to write to stdout as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant