From 752cef329906d860188cda3fdaf7becaa2413940 Mon Sep 17 00:00:00 2001 From: mateeaaaaaaa Date: Thu, 2 Apr 2026 10:10:43 +0300 Subject: [PATCH] fix(security): shell injection in GGML export conversion (#4768) * Fix shell injection in GGML conversion paths * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove test file from security fix PR Move test_save_shell_injection.py to a separate PR to keep this PR focused on the security fix itself. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Han --- unsloth/save.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/unsloth/save.py b/unsloth/save.py index 178178980d..3c318fab02 100644 --- a/unsloth/save.py +++ b/unsloth/save.py @@ -2533,12 +2533,15 @@ def unsloth_convert_lora_to_ggml_and_push_to_hub( ) print(f"The output file will be {output_file}") - command = f"python3 llama.cpp/convert-lora-to-ggml.py {lora_directory_push} {output_file} llama" - try: with subprocess.Popen( - command, - shell = True, + [ + sys.executable, + "llama.cpp/convert-lora-to-ggml.py", + lora_directory_push, + output_file, + "llama", + ], stdout = subprocess.PIPE, stderr = subprocess.PIPE, bufsize = 1, @@ -2550,7 +2553,7 @@ def unsloth_convert_lora_to_ggml_and_push_to_hub( print(line, end = "", flush = True) sp.wait() if sp.returncode != 0: - raise subprocess.CalledProcessError(sp.returncode, command) + raise subprocess.CalledProcessError(sp.returncode, sp.args) except subprocess.CalledProcessError as e: print(f"Error: Conversion failed with return code {e.returncode}") return @@ -2612,12 +2615,15 @@ def unsloth_convert_lora_to_ggml_and_save_locally( ) print(f"The output file will be {output_file}") - command = f"python3 llama.cpp/convert-lora-to-ggml.py {save_directory} {output_file} llama" - try: with subprocess.Popen( - command, - shell = True, + [ + sys.executable, + "llama.cpp/convert-lora-to-ggml.py", + save_directory, + output_file, + "llama", + ], stdout = subprocess.PIPE, stderr = subprocess.PIPE, bufsize = 1, @@ -2629,7 +2635,7 @@ def unsloth_convert_lora_to_ggml_and_save_locally( print(line, end = "", flush = True) sp.wait() if sp.returncode != 0: - raise subprocess.CalledProcessError(sp.returncode, command) + raise subprocess.CalledProcessError(sp.returncode, sp.args) except subprocess.CalledProcessError as e: print(f"Error: Conversion failed with return code {e.returncode}") return