Repository navigation
py/runtime: Check that __dict__ is a dict in import *. - #19673
Open
pablogventura wants to merge 1 commit into
Open
pablogventura wants to merge 1 commit into
pablogventura wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19673 +/- ##
=======================================
Coverage 98.59% 98.59%
=======================================
Files 182 182
Lines 23335 23337 +2
Branches 5 5
=======================================
+ Hits 23006 23008 +2
Misses 328 328
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Code size report: |
Reject a non-dict __dict__ in mp_import_all before mp_obj_dict_get_map, so from m import * raises TypeError instead of crashing when a user object in sys.modules shadows __dict__ with a non-dict value. Signed-off-by: Pablo Ventura <[email protected]>
pablogventura
force-pushed
the
py-import-all-dict-check
branch
from
September 1, 2026 13:25
33bad1e to
2751abe
Compare
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.
Summary
Fixes #19621.
mp_import_allloaded__dict__and passed it tomp_obj_dict_get_mapwithout checking the type. A user object insys.moduleswith a non-dict__dict__(e.g. an instance attribute shadowing the special getter) caused a segfault.Check with
mp_obj_is_dict_or_ordereddictand raiseTypeError(same approach as validating other special-method return types).Testing
tests/import/import_star_non_dict.py(PoC from the issue; CPython raises on assign, MicroPython onimport *; both printTypeError)tests/run-tests.py import/import_star_non_dict.py import/import_star.py import/import_star_error.pyon unix portTrade-offs and Alternatives
Code size (unix
standard,sizetext section, clean rebuild):Does not change instance
__dict__store semantics (still possible to assign a non-dict attribute named__dict__); onlyimport *is hardened.Generative AI
I used generative AI tools when creating this PR, but a human has checked the
code and is responsible for the code and the description above.