Skip to content

Commit 66e68ea

Browse files
committed
image/compress-checksum: sanitize COMPRESS_MAX_THREADS override
A non-numeric or zero COMPRESS_MAX_THREADS was used raw in arithmetic: both read as 0, setting compress_threads=0 (xz/zstd -T0 = 'use all cores') and silently collapsing the cap — the opposite of intent. A non-numeric value also leaked into compress_threads as a string, breaking xz -T. Reject non-numeric/non-positive overrides and fall back to the default 32 before clamping host_threads. Signed-off-by: Igor Pecovnik <igor@armbian.com>
1 parent 9c5e55a commit 66e68ea

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

lib/functions/image/compress-checksum.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ function output_images_compress_and_checksum() {
3636
# threads and reserve ~61GB for marginal wall-time gain. Override per-build
3737
# with COMPRESS_MAX_THREADS (set it >= nproc to disable the cap).
3838
max_threads="${COMPRESS_MAX_THREADS:-32}"
39+
# Guard against a non-numeric or zero override: bash arithmetic reads
40+
# either as 0, which would set compress_threads=0 (xz/zstd -T0 = "use all
41+
# cores") and silently collapse the cap. Fall back to the default 32.
42+
[[ "${max_threads}" =~ ^[0-9]+$ ]] && (( max_threads >= 1 )) || max_threads=32
3943
compress_threads=$host_threads
4044
(( compress_threads > max_threads )) && compress_threads=$max_threads
4145
active_jobs=$(pgrep -cx 'xz|zstd|zstdmt' 2>/dev/null || true)

0 commit comments

Comments
 (0)