feat(doctor): detect fake Windows python.exe stubs and PE subsystem#48581
Open
jinwd-maker wants to merge 2 commits into
Open
feat(doctor): detect fake Windows python.exe stubs and PE subsystem#48581jinwd-maker wants to merge 2 commits into
jinwd-maker wants to merge 2 commits into
Conversation
Adds a 'Windows Python Environment' section to hermes doctor that detects the Windows App Execution Alias trap on Windows 10/11. Windows ships 0-byte python.exe / python3.exe stubs in %LOCALAPPDATA%\Microsoft\WindowsApps. These App Execution Aliases appear first on PATH and mask the real Python installation. Hermes watchdog and cron scripts that resolve 'python' via PATH accidentally pick up the fake stub, which can't run any scripts. Checks performed: - 0-byte stub detection in WindowsApps - PATH resolution check: does 'python' resolve to the fake? - PE subsystem verification: is venv pythonw.exe actually GUI (IMAGE_SUBSYSTEM_WINDOWS_GUI=2) and not CUI? - pythonw resolution: does PATH pick the right one? Includes _pe_subsystem() helper that reads the PE Optional Header subsystem field without external dependencies.
0a7204a to
6dde95b
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
Adds a Windows Python Environment section to
hermes doctorthat detects a common Windows footgun:Windows ships 0-byte
python.exe/python3.exestubs in%LOCALAPPDATA%\Microsoft\WindowsApps. These App Execution Aliases appear first on PATH and mask the real Python installation, silently breaking any subprocess that resolvespythonvia PATH.What it checks
pythonPATH resolutionpythonw.exesubsystempythonwPATH resolutionPE subsystem parser
Includes a zero-dependency
_pe_subsystem()helper that reads the Windows PE Optional Header to determine whether a.exehas:IMAGE_SUBSYSTEM_WINDOWS_GUI(correct for pythonw.exe)IMAGE_SUBSYSTEM_WINDOWS_CUI(correct for python.exe)Example output (affected system)
Fix instructions