h2non / filetype

Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature
https://pkg.go.dev/github.com/h2non/filetype?tab=doc
MIT License
2.05k stars 178 forks source link

ASCII Text Files Starting With Letters "BM" Are Treated As BMP Image Files #117

Open AndrewSverdrup opened 1 year ago

AndrewSverdrup commented 1 year ago

Bug: ASCII Text Files Starting With Letters "BM" Are Treated As BMP Image Files

Example code:

go get github.com/h2non/filetype
package main

import (
    "fmt"
    "github.com/h2non/filetype"
)

func main() {
    file_contents := []byte("BMW")

    kind, _ := filetype.Match(file_contents)
    fmt.Println(kind)
}
go build -o project *.go
./project

Output:

{{image bmp image/bmp} bmp}