1 Commits
Author SHA1 Message Date
janhouse 0e5054f5d0 scan, vex: pass collected files through disk, not argv
A 230-statement VEX file (234 KB) made jq fail with 'Argument list too long'
(--argjson of the accumulated array). Each file is now one JSON object in an
ndjson file, slurped into the report.
2026-11-19 12:49:32 +02:00
2 changed files with 11 additions and 8 deletions

No files matched your search

+6 -5
View File
@@ -161,16 +161,17 @@ runs:
set -euo pipefail set -euo pipefail
url=${PANEL_URL:-${DTRACK_URL%/}/panel-ci/report} url=${PANEL_URL:-${DTRACK_URL%/}/panel-ci/report}
images=$(printf '%s' "$IMAGES" | tr ',' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | { grep -v '^$' || true; } | jq -R . | jq -s .) # no images is fine images=$(printf '%s' "$IMAGES" | tr ',' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | { grep -v '^$' || true; } | jq -R . | jq -s .) # no images is fine
tomls='[]' # Files go through disk, never argv (a big VEX file blows the limit).
: > tomls.ndjson
while IFS= read -r f; do while IFS= read -r f; do
tomls=$(jq --arg p "$f" --rawfile c "$f" '. + [{path: $p, content: $c}]' <<<"$tomls") jq -n --arg p "$f" --rawfile c "$f" '{path: $p, content: $c}' >> tomls.ndjson
done < <(find "$SCAN_PATH" -name osv-scanner.toml -not -path '*/node_modules/*' -not -path '*/.git/*' | head -20) done < <(find "$SCAN_PATH" -name osv-scanner.toml -not -path '*/node_modules/*' -not -path '*/.git/*' | head -20)
vex='[]' : > vex.ndjson
while IFS= read -r f; do while IFS= read -r f; do
vex=$(jq --arg p "$f" --rawfile c "$f" '. + [{path: $p, content: $c}]' <<<"$vex") jq -n --arg p "$f" --rawfile c "$f" '{path: $p, content: $c}' >> vex.ndjson
done < <(find "$SCAN_PATH" -path '*/.vex/*' -name '*.json' -not -path '*/node_modules/*' -not -path '*/.git/*' | sort | head -200) done < <(find "$SCAN_PATH" -path '*/.vex/*' -name '*.json' -not -path '*/node_modules/*' -not -path '*/.git/*' | sort | head -200)
jq -n --arg repo "$REPO" --arg commit "$COMMIT" --arg project "$PROJECT" \ jq -n --arg repo "$REPO" --arg commit "$COMMIT" --arg project "$PROJECT" \
--argjson images "$images" --argjson tomls "$tomls" --argjson vex "$vex" \ --argjson images "$images" --slurpfile tomls tomls.ndjson --slurpfile vex vex.ndjson \
'{repo: $repo, commit: $commit, project: $project, images: $images, osvScannerToml: $tomls, vexFiles: $vex}' > report.json '{repo: $repo, commit: $commit, project: $project, images: $images, osvScannerToml: $tomls, vexFiles: $vex}' > report.json
echo "Reporting $(jq '.images | length' report.json) image(s), $(jq '.osvScannerToml | length' report.json) osv-scanner.toml file(s), $(jq '.vexFiles | length' report.json) VEX file(s) to ${url}" echo "Reporting $(jq '.images | length' report.json) image(s), $(jq '.osvScannerToml | length' report.json) osv-scanner.toml file(s), $(jq '.vexFiles | length' report.json) VEX file(s) to ${url}"
curl -fsS -X POST "$url" -H "X-Api-Key: ${DTRACK_API_KEY}" -H "Content-Type: application/json" \ curl -fsS -X POST "$url" -H "X-Api-Key: ${DTRACK_API_KEY}" -H "Content-Type: application/json" \
+5 -3
View File
@@ -45,11 +45,13 @@ runs:
run: | run: |
set -euo pipefail set -euo pipefail
url=${PANEL_URL:-${DTRACK_URL%/}/panel-ci/vex} url=${PANEL_URL:-${DTRACK_URL%/}/panel-ci/vex}
files='[]' # One JSON object per file on disk (never as an argument: a big VEX
# file blows the argv limit), slurped into the report.
: > vex-files.ndjson
while IFS= read -r f; do while IFS= read -r f; do
files=$(jq --arg p "$f" --rawfile c "$f" '. + [{path: $p, content: $c}]' <<<"$files") jq -n --arg p "$f" --rawfile c "$f" '{path: $p, content: $c}' >> vex-files.ndjson
done < <(find "$VEX_PATH" -name '*.json' -not -path '*/.git/*' | sort | head -500) done < <(find "$VEX_PATH" -name '*.json' -not -path '*/.git/*' | sort | head -500)
jq -n --arg repo "$REPO" --arg commit "$COMMIT" --argjson files "$files" \ jq -n --arg repo "$REPO" --arg commit "$COMMIT" --slurpfile files vex-files.ndjson \
'{repo: $repo, commit: $commit, files: $files}' > vex-report.json '{repo: $repo, commit: $commit, files: $files}' > vex-report.json
echo "Posting $(jq '.files | length' vex-report.json) VEX file(s) to ${url}" echo "Posting $(jq '.files | length' vex-report.json) VEX file(s) to ${url}"
# -f: a rejected file (bad JSON, no justification) fails the job. # -f: a rejected file (bad JSON, no justification) fails the job.