Skip to content

Commit

Permalink
Merge pull request gabriel-vasile#34 from AntoineGirard/fix-dbf-matcher
Browse files Browse the repository at this point in the history
Prevent bad .dbf file
  • Loading branch information
gabriel-vasile committed Jun 17, 2019
2 parents 4a466b0 + 2186a11 commit 8e178e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/matchers/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func Wasm(in []byte) bool {
// Dbf matches a dBase file.
// https://www.dbase.com/Knowledgebase/INT/db7_file_fmt.htm
func Dbf(in []byte) bool {
if len(in) < 4 {
return false
}

// 3rd and 4th bytes contain the last update month and day of month
if !(0 < in[2] && in[2] < 13 && 0 < in[3] && in[3] < 32) {
return false
Expand Down
6 changes: 6 additions & 0 deletions mime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ func TestEmptyInput(t *testing.T) {
}
}

func TestBadBdfInput(t *testing.T) {
if m, _, _ := DetectFile("testdata/bad.dbf"); m != "application/octet-stream" {
t.Errorf("failed to detect bad DBF file")
}
}

func TestGenerateSupportedMimesFile(t *testing.T) {
f, err := os.OpenFile("supported_mimes.md", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
Expand Down
Binary file added testdata/bad.dbf
Binary file not shown.

0 comments on commit 8e178e3

Please sign in to comment.