Avoid shell=True when invoking PACKMOL - #1347
Merged
chrisjonesBSU merged 3 commits intoJul 24, 2026
Merged
Conversation
Popen was called with shell=True and an f-string interpolating a temp-file
path (f"{PACKMOL} < {packmol_inp.name}"). This is a shell-injection
anti-pattern and breaks whenever the temp path contains spaces or shell
metacharacters (e.g. a TMPDIR with spaces).
Pass the executable as an argument list and feed the input file directly as
stdin instead of relying on a shell redirection. Behavior is unchanged (the
shell was only used for the '<' redirection), and PACKMOL is a resolved path
from shutil.which().
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1347 +/- ##
=======================================
Coverage 86.07% 86.07%
=======================================
Files 52 52
Lines 4897 4898 +1
=======================================
+ Hits 4215 4216 +1
Misses 682 682 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
chrisjonesBSU
approved these changes
Jul 24, 2026
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
PACKMOL is currently launched through a shell with an interpolated temp path:
Two problems:
shell=True.TMPDIRunder a user directory with spaces, common on macOS/Windows), the<redirection targets the wrong token and PACKMOL fails.The shell was only being used for the
<input redirection;stdin=PIPEwas set but nothing was ever written to it.Fix
Feed the input file directly as
stdinand pass the executable as an argument list, dropping the shell.PACKMOLis a resolved absolute path fromshutil.which("packmol"), so no shell word-splitting is needed.Behavior is unchanged (PACKMOL reads its config from stdin exactly as before), and the call is now injection-safe and robust to paths with spaces.