Skip to content

Commit f16304a

Browse files
committed
workflows: validate CHUNK_INDEX / CHUNK_COUNT inputs explicitly
workflow_call's `type: number` is enforced at the YAML boundary only; direct API or templated callers can send non-numeric strings that end up in the env. Bash's arithmetic context silently treats non-numeric as 0, so "abc" passed `-lt 1`, hit the silent reset to 1, and the chunk slice ran with a quietly-wrong CHUNK_COUNT. Add explicit guards before any numeric comparison: 1. Regex `^[0-9]+$` on both CHUNK_INDEX and CHUNK_COUNT — fail with "is not a non-negative integer" naming the bad field. 2. Hard-fail CHUNK_COUNT < 1 (was: silent reset to 1) — masking caller bugs is worse than failing loudly. 3. Existing CHUNK_INDEX >= CHUNK_COUNT range check unchanged. Each failure mode emits a distinct error message so a misconfig caller can tell format-error from range-error at a glance.
1 parent d0e480b commit f16304a

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

.github/workflows/infrastructure-download-external.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,29 @@ jobs:
376376
# below GitHub Actions' 256-entry cap. Callers that don't
377377
# know about chunking get CHUNK_COUNT=1 and pass the whole
378378
# thing through (legacy behavior).
379+
#
380+
# Validate the inputs explicitly. workflow_call input
381+
# `type: number` is only enforced at the YAML boundary;
382+
# direct API / curl invocations or templated callers can
383+
# send anything that ends up as a string in the env. Bash's
384+
# arithmetic context silently treats non-numeric as 0,
385+
# which would let "abc" pass `-lt 1` and reset CHUNK_COUNT
386+
# to 1 with no warning. Regex-check first, then range.
379387
CHUNK_INDEX="${{ inputs.CHUNK_INDEX }}"
380388
CHUNK_COUNT="${{ inputs.CHUNK_COUNT }}"
381-
if [[ "${CHUNK_COUNT}" -lt 1 ]]; then CHUNK_COUNT=1; fi
389+
390+
if [[ ! "${CHUNK_INDEX}" =~ ^[0-9]+$ ]]; then
391+
echo "::error::CHUNK_INDEX=${CHUNK_INDEX} is not a non-negative integer" >&2
392+
exit 1
393+
fi
394+
if [[ ! "${CHUNK_COUNT}" =~ ^[0-9]+$ ]]; then
395+
echo "::error::CHUNK_COUNT=${CHUNK_COUNT} is not a non-negative integer" >&2
396+
exit 1
397+
fi
398+
if [[ "${CHUNK_COUNT}" -lt 1 ]]; then
399+
echo "::error::CHUNK_COUNT=${CHUNK_COUNT} must be >= 1" >&2
400+
exit 1
401+
fi
382402
if [[ "${CHUNK_INDEX}" -ge "${CHUNK_COUNT}" ]]; then
383403
echo "::error::CHUNK_INDEX=${CHUNK_INDEX} must be < CHUNK_COUNT=${CHUNK_COUNT}" >&2
384404
exit 1

0 commit comments

Comments
 (0)