py-spy icon indicating copy to clipboard operation
py-spy copied to clipboard

Fix panic in Python 3.12 line number handling

Open sahinfalcon opened this issue 1 year ago • 2 comments

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

sahinfalcon avatar Dec 11 '24 14:12 sahinfalcon

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

zanieb avatar Dec 11 '24 15:12 zanieb

@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.

sahinfalcon avatar Dec 11 '24 15:12 sahinfalcon

thanks for the fix!

benfred avatar Jul 31 '25 18:07 benfred