Skip to content

Commit a22be40

Browse files
joshwilhelmiclaude
andcommitted
[gobby-cli-#958] fix: restore full-stream NUL scan in gcode is_binary
#951 (CodeRabbit triage) reverted the #17356 loop back to a single 8192-byte read while keeping the "null bytes anywhere in the stream" doc comment, so a file with a NUL byte past the first 8KB was misclassified as text and indexed — the late-NUL regression (Gobby #17344). Restore the chunked loop (already bounded by MAX_FILE_SIZE via is_safe_text_file) and add a rationale comment so it is not narrowed again. Validation: - cargo nextest run -p gobby-code -E 'test(/late_nul/)' with AND without default features: 3 passed (skips_content_only/ast_*_late_nul_byte, explicit route). - cargo clippy -p gobby-code [--no-default-features] -- -D warnings: clean. - cargo fmt --all --check: clean. Note: 3 serial_db tests fail locally on a missing/dirty postgres test DB; they pass in CI (which provisions a clean postgres service). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 420ab81 commit a22be40

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

crates/gcode/src/index/security.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,24 @@ pub fn is_binary(path: &Path) -> bool {
4545
Ok(f) => f,
4646
Err(_) => return true,
4747
};
48+
// Scan the whole stream, not just the first 8KB: NUL bytes can appear late
49+
// (a clean prefix followed by binary garbage corrupts the index — gobby-cli
50+
// #17356 / Gobby #17344). The read is bounded: `is_safe_text_file` already
51+
// rejects files larger than MAX_FILE_SIZE before this runs, so the loop reads
52+
// at most that cap. Do not narrow this back to a single read.
4853
let mut buf = [0u8; 8192];
49-
let n = match file.read(&mut buf) {
50-
Ok(n) => n,
51-
Err(_) => return true,
52-
};
53-
buf[..n].contains(&0)
54+
loop {
55+
let n = match file.read(&mut buf) {
56+
Ok(n) => n,
57+
Err(_) => return true,
58+
};
59+
if n == 0 {
60+
return false;
61+
}
62+
if buf[..n].contains(&0) {
63+
return true;
64+
}
65+
}
5466
}
5567

5668
/// Check if a path should be excluded.

0 commit comments

Comments
 (0)