Resource limits and software provenance
Bound the work a script accepts: validate input length, maximum record count and numeric ranges before expensive processing. A check after reading an unlimited stream does not bound memory used to read it. GNU timeout can limit the duration of a command; its default timeout status is normally 124, but options and other failure modes affect the status. Bash ulimit controls selected process resource limits where the operating system supports them. Apply limits in a disposable child or subshell so the caller is not accidentally constrained. Neither timeout nor ulimit provides a secure sandbox or complete descendant cleanup. For dependencies, use trusted distribution channels, reviewed versions and authenticated provenance. Compare a downloaded artifact against an independently trusted checksum or signature before using it. A checksum generated from the same untrusted download does not prove publisher identity. Verify before extraction or execution, reject mismatches and record the source and version. All examples are local and do not download or execute external content. For the modified fixture, compute a digest successfully before asserting that it differs from the trusted expected digest. A verification command failure alone may indicate an I/O error rather than different bytes.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code.
Bound a known slow operation
timeout 0.1s sleep 2rc=$?[[ $rc == 124 ]] || exit 1printf 'status=%s\n' "$rc"Expected stdout:
status=124GNU timeout terminates the authored sleep task. No arbitrary command is accepted.
Apply a child resource limit
before=$(ulimit -Sn) || exit 1( ulimit -Sn 64 || exit 1; child=$(ulimit -Sn) || exit 1; printf 'child=%s\n' "$child" ) || exit 1after=$(ulimit -Sn) || exit 1[[ $after == "$before" ]] && printf 'parent unchanged\n' Expected stdout:
child=64parent unchangedThe fixture requires a hard descriptor limit of at least 64; only the subshell changes its soft limit.
Verify an independently known fixture digest
printf abc > artifact.txt || exit 1printf '%s %s\n' ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad artifact.txt > expected.sha256 || exit 1sha256sum -c expected.sha256 || exit 1printf changed > artifact.txt || exit 1actual=$(sha256sum artifact.txt) || exit 1[[ ${actual%% *} != ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad ]] || exit 1printf 'modified artifact rejected\n' Expected stdout:
artifact.txt: OKmodified artifact rejectedThe digest is fixed for the known bytes abc. The local comparison detects modification; it is not a signature check.
Common mistakes
A timeout is not isolation, and matching a checksum from the same untrusted source is not authenticity.
Practice
Use a known local text fixture and its precomputed SHA-256 digest. Verify the original, modify the fixture, and verify rejection. Test a bounded child command that exceeds its deadline.
Next: System administration automation