Bug report
So I found a really odd bug today. except blocks don't catch exceptions raised when tracing certain statements that themselves "cannot raise". For example:
def f():
breakpoint()
try:
pass # If you raise while tracing this line, the exception isn't caught.
except:
...
try:
42 # Ditto.
except:
...
try:
return # Ditto.
except:
...
A couple of observations:
- Exceptions raised while tracing other "normal" statements are handled the normal way.
- The code for the exception handling is still present in these examples, even though it's statically unreachable.
- If two or more of these "non-raising" statements occur together in the same block (like several
pass statements in a row), only the last one will have the bug:
def f():
breakpoint()
try:
pass # No bug
pass # No bug
pass # Bug
except:
...
I haven't invested any time into figuring out what the root cause is, I've just been poking at it with code examples. It's definitely a bug in the bytecode compiler though, not the interpreter (dis shows missing exception table entries). Probably something to do with how we emit exception tables for NOP or anything that unwinds the block stack, if I had to guess?
(This also affects 3.12, and maybe even earlier versions, but only tagging for 3.13 and newer since I don't think this is a "security" issue.)
Bug report
So I found a really odd bug today.
exceptblocks don't catch exceptions raised when tracing certain statements that themselves "cannot raise". For example:A couple of observations:
passstatements in a row), only the last one will have the bug:I haven't invested any time into figuring out what the root cause is, I've just been poking at it with code examples. It's definitely a bug in the bytecode compiler though, not the interpreter (
disshows missing exception table entries). Probably something to do with how we emit exception tables forNOPor anything that unwinds the block stack, if I had to guess?(This also affects 3.12, and maybe even earlier versions, but only tagging for 3.13 and newer since I don't think this is a "security" issue.)