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.13k stars 177 forks source link

tar file not being recognized #113

Open marcosnils opened 2 years ago

marcosnils commented 2 years ago

:wave: filetype happy user here! Today someone opened an issue in my bin project (https://github.com/marcosnils/bin/issues/140) which led me here.

Filetype is not being able to detect the tar archive inside this gzipped file here https://github.com/sass/dart-sass/releases/download/1.52.3/dart-sass-1.52.3-linux-x64.tar.gz. However, tar -xf works and running file <dart-sass-1.52.3-linux-x64.tar> correctly detects the filetype.

Clearly seems like the file MIME headers are not being properly set. Still.. it's interesting how file still detects it as a tar archive even if the extension is removed.

file -i pepe 
pepe: application/x-tar; charset=binary

Any pointers here?

marcosnils commented 2 years ago

I see it's coming from here: https://sources.debian.org/src/file/1%3A5.39-3/src/funcs.c/#L296

Seems like file still tries to parse the file regardless if the MIME headers are found or not... I think I'll change bin to do a similar approach instead of just relying on MIME headers.