Skip to content

mime: ExtensionsByType is non-deterministic for image/jpeg #39283

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

Closed
chowey opened this issue May 27, 2020 · 2 comments
Closed

mime: ExtensionsByType is non-deterministic for image/jpeg #39283

chowey opened this issue May 27, 2020 · 2 comments

Comments

@chowey
Copy link

chowey commented May 27, 2020

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

$ go version
go version go1.14.3 darwin/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}/Library/Caches/go-build"
GOENV="${HOME}/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY="${PRIVATE_REPO}"
GONOSUMDB="${PRIVATE_REPO}"
GOOS="darwin"
GOPATH="${HOME}/go"
GOPRIVATE="${PRIVATE_REPO}"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/8p/p5rdrmpd5n1gwqv8c6dxb0hc0000gn/T/go-build696615722=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I ran the following code:

https://play.golang.org/p/oVTZQTyxzS_q

The relevant bit is here:

exts, _ := mime.ExtensionsByType("image/jpeg")

What did you expect to see?

I expected to see a consistent result. One of the following would have worked, so long as it were deterministic:

  • [.jpg]
  • [.jpeg]
  • [.jpg .jpeg]
  • [.jpeg .jpg]

What did you see instead?

I saw either [.jpg] or [.jpeg], which changed as I re-ran the program.

Perhaps these extensions are completely interchangeable, but I think they should be deterministic. This affects e.g. unit tests which rely on ExtensionsByType somewhere in the code path.

(Personally, I prefer .jpg over .jpeg.)

@tpaschalis
Copy link
Contributor

tpaschalis commented May 27, 2020

FYI, it seems similar to issue #36524 mime: wrong extensions list for content type "image/jpeg" when using built-in types.

A fix was cherry-picked back in Feb 25, but seems like it didn't find its way in the initial Go 1.14.3 tag. I don't know if it was backported in a later stage, or if it will just be released alongside 1.15.

Could you try re-running your example with the latest version of Go, maybe using gotip? It seems to be working correctly for me.

EDIT: Here's what I'm getting from building what's currently in the master branch and the playground example.

$ gotip run ~/main.go
[.jpe .jpeg .jpg]

@ianlancetaylor
Copy link
Member

Yes, this should be fixed in the upcoming 1.15 release. Sorry for the difficulties.

@golang golang locked and limited conversation to collaborators May 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants