h2non / filetype

Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature

Home Page:https://pkg.go.dev/github.com/h2non/filetype?tab=doc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

AndrewSverdrup opened this issue · comments

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}