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

Fix panic in Python 3.12 line number handling #736

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sahinfalcon
Copy link

The read_varint function would panic when trying to read past the end of the line table. This fix adds bounds checking and returns Option to handle this case gracefully.

Changes:

  1. Modified read_varint to return Option and added bounds checking
  2. Modified read_signed_varint to handle the Option return type
  3. Updated CompactCodeObjectImpl macro to handle Option return types with unwrap_or(0)

Fixes #735

The read_varint function would panic when trying to read past the end of
the line table. This fix adds bounds checking and returns Option<usize>
to handle this case gracefully.

Fixes benfred#735
@sahinfalcon sahinfalcon reopened this Dec 11, 2024
@zanieb
Copy link
Contributor

zanieb commented Dec 11, 2024

Nice! Do you know what the user-facing effect of this is? What happens when the delta is unwrapped to zero?

@sahinfalcon
Copy link
Author

@zanieb It will assume that code is on the same line as the previous code and not crash with an index out of bounds error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

panic with Python 3.12 on Linux
3 participants