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

image/jpeg: unsupported JPEG feature: luma/chroma subsampling ratio #62421

Closed
benjiro29 opened this issue Sep 1, 2023 · 8 comments
Closed

image/jpeg: unsupported JPEG feature: luma/chroma subsampling ratio #62421

benjiro29 opened this issue Sep 1, 2023 · 8 comments
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@benjiro29
Copy link

benjiro29 commented Sep 1, 2023

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

go version go1.21.0 linux/amd64

Does this issue reproduce with the latest release?

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

go env Output
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/root/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/root/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='0'
GOMOD='/dev/null'
GOWORK='/root/Indribell/go.work'
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 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2633292476=/tmp/go-build -gno-record-gcc-switches'

What did you do?

img, _, err = image.Decode(reader)
if err != nil {
	return Log.Error(err, `Decode`)
}

https://asuracomics.com/wp-content/uploads/2022/07/Untitled-1.jpg
https://asuracomics.com/wp-content/uploads/2021/12/heavenlydemoninstructor-1.jpg

What did you expect to see?

No error

What did you see instead?

unsupported JPEG feature: luma/chroma subsampling ratio)

While the images are displayed correctly in multiple programs, Go Image can simply not decode them without erroring out.

@ianlancetaylor ianlancetaylor changed the title Image : unsupported JPEG feature: luma/chroma subsampling ratio image/jpeg : unsupported JPEG feature: luma/chroma subsampling ratio Sep 1, 2023
@ianlancetaylor
Copy link
Contributor

CC @nigeltao

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 1, 2023
@dmitshur dmitshur added this to the Backlog milestone Sep 2, 2023
@dmitshur dmitshur changed the title image/jpeg : unsupported JPEG feature: luma/chroma subsampling ratio image/jpeg: unsupported JPEG feature: luma/chroma subsampling ratio Sep 2, 2023
@dmitshur
Copy link
Contributor

dmitshur commented Sep 2, 2023

Issues #13614 and #2362 appear to be related.

@nigeltao
Copy link
Contributor

nigeltao commented Oct 7, 2023

Those asuracomics.com links don't work for me, but I suspect that this is a duplicate of #2362.

In hindsight, the image.YCbCrSubsampleRatio design, which only supports a fixed allow-list of luma/chroma subsampling ratios, was a mistake. But, due to Go 1 compatibility, fixing that is not going to be easy, per #2362 (comment)

@nigeltao nigeltao closed this as completed Oct 7, 2023
@nigeltao
Copy link
Contributor

nigeltao commented Oct 7, 2023

Issue #13614 is unrelated, as it involves Go's JPEG encoder. This issue is about the decoder.

@benjiro29
Copy link
Author

benjiro29 commented Oct 7, 2023

Those asuracomics.com links don't work for me, but I suspect that this is a duplicate of #2362.

Updated link that is working:

https://asuratoon.com/wp-content/uploads/2022/07/Untitled-1.jpg
https://asuratoon.com/wp-content/uploads/2021/12/heavenlydemoninstructor-1.jpg

Fyi, in regards to #2362 comment

and I'm not sure if it's worth the cost, given how infrequent such images

My ratio of images found with this issue was about ~20% on that website alone.

@KevinColemanInc
Copy link

@benjiro29 (or anyone else), is there a quick fix for this? My guess is to use a c-library to parse it, but i'd prefer a pure golang solution.

@benjiro29
Copy link
Author

@benjiro29 (or anyone else), is there a quick fix for this? My guess is to use a c-library to parse it, but i'd prefer a pure golang solution.

There is zero solutions for this issue. I bypass it by simply not handling images that have this issue and keeping the original size (with consequences if its like a 8MB image that is now being displayed as a thumb image)...

As long as the attitude prevails of "we made a booboo by assuming nobody will run into this and now we fear fixing it because of backward compatibility" ... with that attitude, it will never get fixed. This issue is known for 13 years, ...

You can not rely on other image handling libraries, as all fall back to Go its build in Image in some way. Tried a bunch, all had the same issue.

Your only option is to waste a tone of time by including a external library and going to cgo route or include a external program that you call for dealing with those images. Both are horrible solutions.

So, do like the go dev's. ignore the issue by keeping the original image and let the dice roll.

@KevinColemanInc
Copy link

You can not rely on other image handling libraries, as all fall back to Go its build in Image in some way. Tried a bunch, all had the same issue.

Calling imagemagick fixes the issue, but this is 4-20x worse than pure-go resizing. Our supported qps drops from 25 to 15 qps (without scaling up more servers)

I can't ignore the issue, b/c our ML models can't support large images. and go-lang is the most central place for resizing the images before passing them to the ML models.

My tentative plan is to try to decode with golang. If that fails with the chroma error, fallback to imagemagick. Unfortunately our ci system doesn't support cgo.

If anyone cares to see my imagemagick code:

func img_resize(imageData []byte) ([]byte, error) {
	//maxSizeSetting := "jpeg:extent=" + strconv.Itoa(300) + "kb"
	maxSizeSetting := "jpeg:extent=300kb"
	minResizeSetting := "512x512>"   // resize image down to 512
	maxResizeSetting := "1024x1024<" // resize image up to 1024
	params := []string{
		"-", // input image is passed via stdin
		"-define", maxSizeSetting,
		"-resize", minResizeSetting,
		"-resize", maxResizeSetting,
		"-limit", "thread", "1",
		"-", // output is stdout
	}
	cmd := exec.Command("convert", params...)
	cmd.Env = append(cmd.Env, "MAGICK_THROTTLE=50")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest 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