From ceefaddc97f4e689d35af60d354f410d3ffeb527 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 16 Apr 2026 13:39:08 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=20Fix=20potential=20shell=20comman?= =?UTF-8?q?d=20injection=20in=20convert=5Fpdfs.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces unquoted parameter usage and vulnerable external subshell command invocations (`basename`, `sed`) with robust built-in bash parameter expansions. This fixes a potential injection and word-splitting vector where maliciously crafted filenames could allow arbitrary code execution during the conversion process. Co-authored-by: dynamikdev <717692+dynamikdev@users.noreply.github.com> --- scripts/convert_pdfs.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/convert_pdfs.sh b/scripts/convert_pdfs.sh index 487ebc9..f965322 100755 --- a/scripts/convert_pdfs.sh +++ b/scripts/convert_pdfs.sh @@ -23,10 +23,16 @@ find "$BASE_DIR" -type f -name "*.pdf" | while read -r pdf_file; do # Rename pages to have leading zeros for better sorting (page-1.jpg -> page-01.jpg) for f in "$output_dir"/page-*.jpg; do - # Extract the number, strip any leading dash and the .jpg extension - num=$(basename "$f" .jpg | sed 's/page-//') + # Check if the file exists (handles the case where no files match the glob) + [ -e "$f" ] || continue + + # Extract the number securely using bash parameter expansion + base="${f##*/}" + base="${base%.jpg}" + num="${base#page-}" + # Remove leading zero to avoid octal interpretation in bash printf - clean_num=$(echo $num | sed 's/^0*//') + clean_num="${num#"${num%%[!0]*}"}" # If the number was 0 or 00, clean_num might be empty if [ -z "$clean_num" ]; then clean_num=0; fi