Skip to content

diff: look for NUL bytes in the first st_blksize bytes only - #385

Open
binhvq wants to merge 4 commits into
uutils:mainfrom
binhvq:binary-probe-first-block
Open

binhvq wants to merge 4 commits into
uutils:mainfrom
binhvq:binary-probe-first-block

Conversation

@binhvq

@binhvq binhvq commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #349.

GNU diff decides a file is binary from its first read buffer only, and that buffer is st_blksize bytes for each file. We always looked at 16 KiB, so a NUL between 4 KiB and 16 KiB made us print "Binary files ... differ" where GNU shows the diff.

The size now comes from the metadata of the file that was read (and of stdin), per file like GNU. Checked against GNU diff 3.12 with the NUL just before and after 4096, 8192 and 16384, for files, stdin from a file and stdin from a pipe, and with a /proc file whose st_blksize is 1024. Where there is no st_blksize (Windows, WASI) it stays at 16 KiB.

The test skips itself if the temp dir's block size is not below the test data size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

diff - binary detection looks at 16 KiB instead of the file's first buffer

1 participant