fix: skip binary files in content search#3006
Open
dgageot wants to merge 1 commit into
Open
Conversation
docker-agent
reviewed
Jun 5, 2026
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
This PR correctly implements binary file detection for search_files_content by sniffing the first 512 bytes of each file. The implementation is clean, consistent with existing patterns, and well-tested.
Approach: Checks for null bytes first (fast path for ELF, ZIP, etc.), then falls back to http.DetectContentType for magic-byte-based detection (PDF, PNG, and other formats). Silent skip on detection errors is consistent with how the rest of the walk handles I/O failures.
Test coverage: Unit tests cover empty input, plain text, UTF-8 text, ELF, PNG, PDF, and an end-to-end integration test with mixed text/binary files in a directory — adequate for the scope of change.
No bugs found in the changed code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
search_files_contenttool now sniffs file headers to detect and skip binary files before attempting to read them. This prevents slow reads, unnecessary memory usage, and potential encoding errors when encountering binary data during search operations.The implementation detects ELF binaries, PNG images, PDF files, and other common binary formats by checking magic bytes at the start of files. Tests cover all major detection patterns and verify end-to-end behavior with mixed text and binary files in a directory.