From 0315c43a2741d8d1e5372ed164ac390936acadcf Mon Sep 17 00:00:00 2001 From: Julien Chastang Date: Tue, 10 Mar 2026 16:37:21 -0600 Subject: [PATCH] binary check. rely on perl instead --- .github/workflows/no-large-files.yml | 34 +++++++++++++--------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/.github/workflows/no-large-files.yml b/.github/workflows/no-large-files.yml index eea34ad..ebad8a7 100644 --- a/.github/workflows/no-large-files.yml +++ b/.github/workflows/no-large-files.yml @@ -42,26 +42,24 @@ jobs: exit "$bad" - # generating false positives. May revisit - # - # - name: Fail on likely-binary files - # run: | - # set -euo pipefail + - name: Fail on likely-binary files + run: | + set -euo pipefail - # base="${{ github.event.pull_request.base.sha }}" - # head="${{ github.sha }}" + base="${{ github.event.pull_request.base.sha }}" + head="${{ github.sha }}" - # mapfile -t files < <(git diff --name-only --diff-filter=AM "$base" "$head") + mapfile -t files < <(git diff --name-only --diff-filter=AM "$base" "$head") - # bad=0 - # for f in "${files[@]}"; do - # [ -f "$f" ] || continue + bad=0 + for f in "${files[@]}"; do + [ -f "$f" ] || continue - # # Heuristic: if file contains NUL bytes, treat as binary - # if LC_ALL=C grep -qU $'\x00' "$f"; then - # echo "::error file=$f::Likely binary file (contains NUL byte)." - # bad=1 - # fi - # done + # perl -0777 slurps file; exit 0 if a NUL byte (\x00) is present + if perl -0777 -ne 'exit(/\x00/ ? 0 : 1)' "$f"; then + echo "::error file=$f::Likely binary file (contains NUL byte)." + bad=1 + fi + done - # exit "$bad" + exit "$bad"