Go: x/image/webp: "non-Alpha VP8X is not implemented" error while doing DecodeConfig

Created on 10 Apr 2020  ·  7Comments  ·  Source: golang/go

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

$ go version
go version go1.14.1 linux/amd64

Does this issue reproduce with the latest release?

yep.

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

(probably irrelevant so won't include yet)

What did you do?

Quick repro program:

package main

import (
    _ "golang.org/x/image/webp"
    "image"
    "os"
    "fmt"
)

func main() {
    if len(os.Args) <= 1 {
        fmt.Fprintf(os.Stderr, "Usage: %s [filename...]", os.Args[0])
    }
    for i := 1; i < len(os.Args); i++ {
        fn := os.Args[i]
        f, e := os.Open(fn)
        if e != nil {
            panic("os.Open: " + e.Error())
        }
        cfg, ifmt, e := image.DecodeConfig(f)
        _ = f.Close()
        if e == nil {
            fmt.Printf("%s ok: %s %#v\n", fn, ifmt, cfg)
        } else {
            fmt.Printf("%s err: %v\n", fn, e)
        }
    }
}

ran it against https://0x0.st/iS94.webp

What did you expect to see?

No error. If it's able to recognize format and extract metadata, it should return them without raising error, even if it wouldn't be able to fully decode image.

What did you see instead?

tumblr_py63povN441yw147jo1_250.webp err: webp: non-Alpha VP8X is not implemented

NeedsInvestigation

Most helpful comment

oops, didn't notice already closed https://github.com/golang/go/issues/25738 before posting this.
but it wasn't fixed, and closed by reporter because they found some cgo based lib with different API, and that's not very acceptable solution for me.

All 7 comments

oops, didn't notice already closed https://github.com/golang/go/issues/25738 before posting this.
but it wasn't fixed, and closed by reporter because they found some cgo based lib with different API, and that's not very acceptable solution for me.

quite simple tweak of source should sorta fix this at least for me (I only use DecodeConfig to detect file format and check image dimensions)

diff --git a/webp/decode.go b/webp/decode.go
index f77a4eb..26d7dc1 100644
--- a/webp/decode.go
+++ b/webp/decode.go
@@ -126,9 +126,6 @@ func decode(r io.Reader, configOnly bool) (image.Image, image.Config, error) {
                                alphaBit        = 1 << 4
                                iccProfileBit   = 1 << 5
                        )
-                       if buf[0] != alphaBit {
-                               return nil, image.Config{}, errors.New("webp: non-Alpha VP8X is not implemented")
-                       }
                        widthMinusOne = uint32(buf[4]) | uint32(buf[5])<<8 | uint32(buf[6])<<16
                        heightMinusOne = uint32(buf[7]) | uint32(buf[8])<<8 | uint32(buf[9])<<16
                        if configOnly {
@@ -138,6 +135,9 @@ func decode(r io.Reader, configOnly bool) (image.Image, image.Config, error) {
                                        Height:     int(heightMinusOne) + 1,
                                }, nil
                        }
+                       if buf[0] != alphaBit {
+                               return nil, image.Config{}, errors.New("webp: non-Alpha VP8X is not implemented")
+                       }
                        wantAlpha = true

                default:

I'm not really sure how to contribute to x/image repo yet.
Maybe someone could just land this tweak?
It doesn't fix general lack of robustness for decoding, and ColorModel will probably be wrong in some cases, but ColorModel was already wrong if VP8L would've came after alpha so I don't think this makes it worse, and it would also make webp usable for my use case (just get format and dimensions) (right now it isn't, because it fails on images ocuring in real life).

@nigeltao

Change https://golang.org/cl/230137 mentions this issue: webp: make DecodeConfig less strict re VP8X flags

https://play.golang.org/p/Yf77mdmNEZM small self-contained repro (not smallest possible though, just random small gif I found online and converted to webp)

Change https://golang.org/cl/249445 mentions this issue: fix(webp): decode non-alpha vp8x error.

Seems to be fixed by https://github.com/golang/image/commit/3a743ba83854117dc10e2af4c7213cd946169367
Repro now executes without problems in both local testing and play.golang.org.
Therefore closing.

Was this page helpful?
0 / 5 - 0 ratings