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

tar file not being recognized

marcosnils opened this issue Β· comments

πŸ‘‹ filetype happy user here! Today someone opened an issue in my bin project (marcosnils/bin#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?

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.