Issue 36053: pkgutil.walk_packages jumps out from given path if there is package with the same name in sys.path (original) (raw)
Issue36053
Created on 2019-02-20 16:37 by karkucik, last changed 2022-04-11 14:59 by admin.
Pull Requests | |||
---|---|---|---|
URL | Status | Linked | Edit |
PR 11956 | open | karkucik,2019-02-20 16:44 |
| Messages (6) | | | | | | | | | | | | | |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | ---------------------- | | | ------------------ | | | --------- | | ------------------ | ------------------------------------ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| msg336111 - (view) | Author: Piotr Karkut (karkucik) * | Date: 2019-02-20 16:37 | | | | | | | | | | | |
| When walk_packages encounter a package with a name that is available in sys.path, it will abandon the current package, and start walking the package from the sys.path. Consider this file layout: ``` PYTHONPATH/ ├──package1/ | ├──core | | ├──some_package/ | | | ├──__init__.py | | | └──mod.py | | └──__init__.py | └──__init__.py └──some_package/ | ├──__init__.py | └──another_mod.py └──__init__.py ``` The result of walking package1 will be: ``` >> pkgutil.walk_packages('PYTHONPATH/package1') ModuleInfo(module_finder=FileFinder('PYTHONPATH/package1/core'), name='some_package', ispkg=True) ModuleInfo(module_finder=FileFinder('PYTHONPATH/some_package), name='another_mod', ispkg=False) ``` I'm not sure if it is a security issue, but it definitely should not jump off the given path. |
| msg339028 - (view) | Author: Piotr Karkut (karkucik) * | Date: 2019-03-28 10:06 | | | | | | | | | | | |
| Bump | | | | | | | | | | | | | |
| msg339573 - (view) | Author: Alyssa Coghlan (ncoghlan) * | Date: 2019-04-07 11:52 | | | | | | | | | | | |
| Piotr: does it always jump out, or does it only jump out if the relevant module has already been imported? (The tests for walk_packages are relatively weak and never generate conflicting names, so it's entirely plausible that there are caching side effects that make it do strange things) | | | | | | | | | | | | | |
| msg339603 - (view) | Author: Piotr Karkut (karkucik) * | Date: 2019-04-08 09:14 | | | | | | | | | | | |
| Nick: From what I've checked, it jumps in case the module is already imported. The problem is that the original implementation is quite naive, and it's trying to import the module before looking for it in `sys.modules` - So if the module with a conflicting name is in PYTHONPATH and has higher priority, it'd be imported instead of the correct one. And then, as the module is imported, it'd be available in `sys.modules`. | | | | | | | | | | | | | |
| msg343747 - (view) | Author: Piotr Karkut (karkucik) * | Date: 2019-05-28 08:22 | | | | | | | | | | | |
| Bump? | | | | | | | | | | | | | |
| msg348381 - (view) | Author: Piotr Karkut (karkucik) * | Date: 2019-07-24 12:03 | | | | | | | | | | | |
| bump | | | | | | | | | | | | | |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:59:11 | admin | set | github: 80234 |
2019-07-24 12:03:00 | karkucik | set | messages: + |
2019-05-28 08:22:35 | karkucik | set | messages: + |
2019-04-08 09:14:06 | karkucik | set | messages: + |
2019-04-07 11:52:51 | ncoghlan | set | messages: + |
2019-04-03 08:44:42 | SilentGhost | set | nosy: + ncoghlanversions: - Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7 |
2019-03-28 10:06:49 | karkucik | set | messages: + |
2019-02-20 16:44:56 | karkucik | set | keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest11982> |
2019-02-20 16:42:04 | karkucik | set | title: pkgutil.walk_packages jumps out from given path if there is package with the same name in sys.pah -> pkgutil.walk_packages jumps out from given path if there is package with the same name in sys.path |
2019-02-20 16:37:07 | karkucik | create |