fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

fix: binary file check misses binary files where first byte is null (#1054)

While searching for a short string of text, it returned some TTF files.
I downloaded one from the source repo and checked it locally with a hex
viewer to confirm. A bit of poking around this logic bug.

I found a second more recent instance of the same bug that seems to be
a copy/paste error.

+4 -4
+2 -2
index/index_test.go
··· 3409 3409 t.Errorf("Check(%q): %v", text, skip) 3410 3410 } 3411 3411 } 3412 - for _, text := range []string{"zero\x00byte", "xx", "0123456789abcdefghi"} { 3412 + for _, text := range []string{"zero\x00byte", "\x00starts with null byte", "xx", "0123456789abcdefghi"} { 3413 3413 if skip := docChecker.Check([]byte(text), 15, false); skip == SkipReasonNone { 3414 3414 t.Errorf("Check(%q) succeeded", text) 3415 3415 } ··· 3421 3421 t.Errorf("Check(%q): %v", text, skip) 3422 3422 } 3423 3423 } 3424 - for _, text := range []string{"zero\x00byte", "xx"} { 3424 + for _, text := range []string{"zero\x00byte", "\x00starts with null byte", "xx"} { 3425 3425 if skip := docChecker.Check([]byte(text), 15, true); skip == SkipReasonNone { 3426 3426 t.Errorf("Check(%q) succeeded", text) 3427 3427 }
+2 -2
index/shard_builder.go
··· 546 546 // Skip binary check if already computed (e.g., by Builder.Add 547 547 // which calls DocChecker.Check before docs reach buildShard). 548 548 if doc.Category == FileCategoryMissing { 549 - if index := bytes.IndexByte(doc.Content, 0); index > 0 { 549 + if index := bytes.IndexByte(doc.Content, 0); index >= 0 { 550 550 doc.SkipReason = SkipReasonBinary 551 551 } 552 552 } ··· 686 686 return SkipReasonTooSmall 687 687 } 688 688 689 - if index := bytes.IndexByte(content, 0); index > 0 { 689 + if index := bytes.IndexByte(content, 0); index >= 0 { 690 690 return SkipReasonBinary 691 691 } 692 692