From c9f7b81f013eca9d25d956f1f644c05ec9814ae0 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Tue, 24 Feb 2026 21:16:10 +0100 Subject: fix: improve input validation and error reporting Validate the nice value is an integer in [-20, 19] at startup rather than letting nice(1) fail with a cryptic error at encode time. In encode_one, move the "Processing" message after the empty-string guard so it is not printed for blank lines, include the filename in the "Not found" error, and add a readability check so unreadable files are rejected with a clear message before ffprobe is invoked. Validate that the encode file (-f) exists before entering the read loop, exiting with a usage error rather than a silent empty run. --- transcode.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/transcode.sh b/transcode.sh index 15dba25..500111d 100755 --- a/transcode.sh +++ b/transcode.sh @@ -557,6 +557,11 @@ if [[ $SAVING -eq 1 ]]; then } fi +if [[ ! "$NICE_VALUE" =~ ^-?[0-9]+$ ]] || ((NICE_VALUE < -20 || NICE_VALUE > 19)); then + error "Invalid nice value (must be an integer between -20 and 19):" "$NICE_VALUE" + exit $EXIT_USAGE_ERROR +fi + # Remove temporary output files created during encoding. # Registered via trap EXIT so it runs on normal exit and on failures # shellcheck disable=SC2329 @@ -584,11 +589,16 @@ trap cleanup EXIT # EXIT_OK on success or if skipped; EXIT_RUNTIME_FAILURE on failure. encode_one() { local file="$1" - msg "Processing:" "$file" [[ -z "$file" ]] && return $EXIT_OK + + msg "Processing:" "$file" [[ ! -f "$file" ]] && { - error "Not found" + error "Not found:" "$file" + return $EXIT_RUNTIME_FAILURE + } + [[ ! -r "$file" ]] && { + error "File is not readable:" "$file" return $EXIT_RUNTIME_FAILURE } @@ -752,6 +762,10 @@ encode_one() { STATUS=$EXIT_OK if [[ -n $ENCODE_FILE ]]; then + [[ -f "$ENCODE_FILE" ]] || { + error "Encode file not found:" "$ENCODE_FILE" + exit $EXIT_USAGE_ERROR + } while IFS= read -r file || [[ -n "$file" ]]; do encode_one "$file" || STATUS=$EXIT_RUNTIME_FAILURE done <"$ENCODE_FILE" -- cgit v1.3.1