File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments