{{ message }}
Fix find_spec crash with C extension loaders#2190
Open
karlhillx wants to merge 2 commits into
Open
Conversation
When find_spec() triggers loading of a parent package whose C extension raises a non-Exception error (Abort, SystemExit, etc.), file_and_path_for_module() would propagate it instead of returning (None, []). Catch BaseException to handle C-level crashes and other non-Exception throws from the import machinery. Regression test for coveragepy#2189.
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #2189
When coverage calls importlib.util.find_spec() on a submodule
(e.g. pikepdf.form), it can trigger loading of the parent package
(pikepdf). If pikepdf's C extension raises a non-Exception error
(e.g. Abort from a broken nanobind extension), that error would
propagate through file_and_path_for_module() and crash the process.
The fix changes except Exception to except BaseException in
file_and_path_for_module(), so non-Python exceptions are caught
and the function gracefully returns (None, []).
Regression test included.