Repository navigation
python: Use argument lists instead of shell=True for subprocess - #7703
Merged
Merged
Conversation
In grass.imaging, build the ffmpeg command for writeAvi as an argument list, splitting the caller-provided option strings with shlex. Convert the readAvi command to a list as well; as a plain string without a shell it failed with FileNotFoundError on non-Windows platforms. In pygrass grid, build the g.region command in set_region as a list and run tile commands in cmd_exe through grass.script.core.Popen, which resolves the executable and handles script tools on Windows, instead of passing shell=True or a platform-dependent shell flag. Fixes 6 Bandit B602 (subprocess_popen_with_shell_equals_true) alerts.
petrasovaa
requested changes
Jul 14, 2026
cwhite911
added a commit
to cwhite911/grass
that referenced
this pull request
Jul 15, 2026
Address review feedback: instead of skipping Bandit B607 globally (which would also stop catching newly introduced violations), suppress it inline at each existing call site. These are developer, build, and test helpers that invoke known tools (git, gh, svn, msgfmt, mdl, man, grass) by name, intentionally resolved through PATH, the same rationale as the already-skipped B603. The g.region call in pygrass grid is addressed separately in the shell=True cleanup (OSGeo#7703).
Address review feedback: replace the "from grass.script import core as gcore" module-alias import with a direct Popen import, and update cmd_exe()'s three call sites accordingly. Also switch set_region()'s two subprocess.Popen calls to the same grass.script Popen used by cmd_exe(). That Popen resolves the executable via shutil.which() and re-enables shell=True on Windows for script tools like g.region, which the removed shell=True previously provided; plain subprocess.Popen would fail to launch g.region on Windows. Assisted by Claude Code.
petrasovaa
approved these changes
Jul 15, 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.
Fixes the 6 Bandit B602 (
shell=True, error severity) code scanning alerts in non-vendored code, as a robustness and portability cleanup:grass.imaging.images2avi.writeAvi: the ffmpeg command was assembled by string concatenation and run through the shell. Now built as an argument list, with the caller-providedinputOptions/outputOptionsstrings split viashlex.split(), preserving the previous argument semantics.grass.imaging.images2avi.readAvi: the command was a plain string passed withoutshell=True, which raisesFileNotFoundErroron non-Windows platforms (No such file or directory: 'ffmpeg -i input.avi im%d.jpg'), so this also fixes readAvi being broken on Linux and macOS.grass.pygrass.modules.grid:set_region()built ag.regioncommand string for the shell; now an explicit argument list.cmd_exe()passedshell=(sys.platform == "win32"); it now usesgrass.script.core.Popen, which resolves the executable withshutil.which()and handles script tools on Windows, so the platform flag is no longer needed.Verified locally:
GridModule(r.slope.aspect, 4 tiles, 2 processes) produces output bit-identical to a non-tiled run (r.mapcalcdiff, max abs diff 0)writeAvi/readAviround trip with real ffmpeg (5 frames, correct shapes), exercising the shlex option splittingset_region()call confirmed to apply the regionThis is part of a larger effort to work through the open code scanning alerts, grouped into small PRs by issue type.
Written with the assistance of Claude Code.