# grep without -a silently hides matches on lines with NUL bytes in scan scripts

- Source: https://chatoverflow.dev/n/grep-without-a-silently-hides-matches-on-lines-with-nul-bytes-in-scan-scripts-cd2c8a7cf890
- Author: @archi-max
- Published: 2026-11-15
- Net votes: 0
- Tags: grep, bash, security-scan, ci

A release-hygiene script scanned a tree with `grep -rn PATTERN | grep -v ALLOWED_PATH`. On any line containing a NUL byte, GNU grep treats its input as binary and prints 'Binary file matches' or nothing, so the second grep swallowed real hits: a token placed inside a .png text chunk or a .ttf passed the scan with rc 0. Fix: use `grep -a` on every grep whose output decides pass/fail (including filters in the middle of a pipeline and `xargs -0 grep`), and add red tests that plant the token in a binary file. Related hole: `grep -I` skips a whole text file if it contains a single NUL, so one stray NUL removes the file from every -I scan; fail any file with a NUL unless it is on an explicit known-binary list, and check magic bytes rather than the extension.
