Skip to content

decode: wasm error: invalid table access #3

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
KevinColemanInc opened this issue May 13, 2024 · 11 comments
Closed

decode: wasm error: invalid table access #3

KevinColemanInc opened this issue May 13, 2024 · 11 comments

Comments

@KevinColemanInc
Copy link

This decoder has the same issue that golang has with certain jpg formats:

golang/go#62421

func img_jpegli(imageData []byte) ([]byte, error) {
	img, err := jpegli.Decode(bytes.NewReader(imageData))
	if err != nil {
		panic(err)
	}

output:

decode: wasm error: invalid table access
wasm stack trace:
        .$13(i32)
        .$6(i32,i32,i32,i32,i32,i32,i32,i32,i32,i32,i32,i32,i32,i32) i32

goroutine 1 [running]:
main.img_jpegli({0x1400034a000, 0x33fab, 0x36000})
        ./gopath/src/github.com/kevincolemaninc/playground/comparison/main.go:226 +0x21c
main.ResizeImageMagick({0x1400011a032, 0xe})
        ./gopath/src/github.com/kevincolemaninc/playground/comparison/main.go:447 +0x650
main.main()
        ./gopath/src/github.com/kevincolemaninc/playground/comparison/main.go:512 +0x238
exit status 2

If you need a test image, can you email me at kcoleman.me/contact? I don't want to post my test image online.

@gen2brain
Copy link
Owner

Yes, a test image would be nice. You can send it to me by email, it is listed on github profile.

@KevinColemanInc
Copy link
Author

actually the image in this Issue has the problem (I verified it locally).

golang/go#54997 (comment)

func img_go(imageData []byte) ([]byte, error) {
	// Decode the image data
	img, format, err := image.Decode(bytes.NewReader(imageData))
	if err != nil {
		return nil, err
	}

@gen2brain
Copy link
Owner

Thanks. Looks like a tricky issue, will check when I find the time. I never seen an image that is Y: 2x2, Cb: 1x1, Cr: 1x2, that would be 4:2:1 as I understand, not the regular case. Will need to check how some other libraries handle this case, but even then, not sure how to represent that image if Go doesn't have support for it, something like explained here maybe golang/go#2362 (comment).

@gen2brain
Copy link
Owner

I guess I could just detect such images and skip raw_data_out and just read scanlines as RGBA, I will see.

@KevinColemanInc
Copy link
Author

Unfortunately,I can't speak on a solution, but we switched to libvips b/c users were uploading these images. Other c-based jpeg decoders also worked (like https://github.com/h2non/bimg)

@gen2brain
Copy link
Owner

Ok, this is fixed in e9c61fe and I tagged a new version. I just use the RGBA read scanlines when the image is YCbCr421. It will be slower than raw data but I don't think that is important in this case.

@gen2brain
Copy link
Owner

I added one more case I found in issues. If you can confirm it works this can be closed.

@KevinColemanInc
Copy link
Author

ok, I will test some images I have and let you know.

@KevinColemanInc
Copy link
Author

KevinColemanInc commented May 14, 2024

I tested v0.2.2 with another unsupported chroma jpg successfully, but the performance isn't great compared to other libraries with both unsupported-chroma and a large "normal" jpgs:

This is the timing and compression results with 1200x1200 213KB unsupported-chroma jpg:

tag description
vipscliTime starts the vipsheader process to get the image's size and then calls vipsthumbnail to resize the image
img_vips https://github.com/davidbyttow/govips/v2/vips - there is a sharpening step in this test
img_bimg https://github.com/h2non/bimg
img_imagemagickcli starts the convert process and communicates via stdin/stdout
img_go native go "image" package
img_jpegli this project
vipscliTime: Time: 175.065583ms, Compression: 125.19%
img_vips: Time: 68.697083ms, Compression: 72.40%
img_bimg: Time: 60.841791ms, Compression: 70.99%
img_imagemagickcli: Time: 143.20625ms, Compression: 119.10%
img_go: Time: 46.167µs, Compression: 0.00%
img_jpegli: Time: 256.516833ms, Compression: 57.47%

These are the processing / load times for resizing and compressing this 19Mb unsplash image with various tools on my Apple M1 Pro 32GB RAM:

vipscliTime: Time: 927.816542ms, Compression: 0.59%
img_vips: Time: 1.491927375s, Compression: 0.35%
img_bimg: Time: 797.620291ms, Compression: 0.33%
img_imagemagickcli: Time: 4.501780875s, Compression: 0.93%
img_go: Time: 4.321412625s, Compression: 0.23%
img_jpegli: Time: 4.625325792s, Compression: 0.23%

The CI system at my job doesn't support cgo, which is why this project caught my eye. I ended up passing images to vips cli via stdin/stdout to process chroma-issue images efficiently.

@gen2brain
Copy link
Owner

You cannot really compare C libraries with optimized assembly instructions and std lib or wasm. It is fine enough that the performance is similar to std, that there is no cgo, and that creates smaller files.

@KevinColemanInc
Copy link
Author

I'll close the issue since the main point has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants