Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: DetectContentType returns 'application/octet-stream' for a TIFF image #61504

Closed
sbinet opened this issue Jul 21, 2023 · 4 comments
Closed
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@sbinet
Copy link
Member

sbinet commented Jul 21, 2023

What version of Go are you using (go version)?

$ go version
go version devel go1.22-f2d709b769 Fri Jul 21 05:39:00 2023 +0000 linux/amd64

Does this issue reproduce with the latest release?

yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/binet/.cache/go-build'
GOENV='/home/binet/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/binet/dev/go/gocode/pkg/mod'
GONOPROXY='gitlab.cern.ch/tile-in-one/tio-go,gitlab.cern.ch/tile-in-one/tio-0021/*'
GONOSUMDB='gitlab.cern.ch/tile-in-one/tio-go,gitlab.cern.ch/tile-in-one/tio-0021/*'
GOOS='linux'
GOPATH='/home/binet/dev/go/gocode'
GOPRIVATE='gitlab.cern.ch/tile-in-one/tio-go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/binet/sdk/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/binet/sdk/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.22-f2d709b769 Fri Jul 21 05:39:00 2023 +0000'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1429939606=/tmp/go-build -gno-record-gcc-switches'

What did you do?

run net/http.DetectContentType on the raw bytes of a TIFF image.

What did you expect to see?

get "image/tiff"

What did you see instead?

"application/octet-stream" (which is the fallback)

@mauri870
Copy link
Member

Can you try the same with the command file yourfile.tiff and see if it also reports as octetstream?

@gopherbot
Copy link

Change https://go.dev/cl/511975 mentions this issue: net/http: add handling of image/tiff in DetectContentType

@sbinet
Copy link
Member Author

sbinet commented Jul 21, 2023

net/http didn't have the magic values for image/tiff.

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 21, 2023
@bcmills bcmills added this to the Backlog milestone Jul 21, 2023
@neild
Copy link
Contributor

neild commented Jul 21, 2023

DetectContentType implements the WHATWG MIME Sniffing standard: https://mimesniff.spec.whatwg.org/#matching-an-image-type-pattern

So far as I can tell, that standard doesn't currently include image/tiff, so we shouldn't add it to DetectContentType.

The right path to adding new types to DetectContentType is to get the WHATWG standard updated first.

@sbinet sbinet closed this as completed Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants