Skip to content

Commit ebb3ef2

Browse files
joshwilhelmiclaude
andcommitted
Merge dev into main: restore gcode late-NUL scan (#958) for the release
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2 parents e7532fa + a22be40 commit ebb3ef2

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)