Skip to content

Commit 9e190ae

Browse files
rolandshoemakergopherbot
authored andcommitted
webp: disallow multiple VP8X chunks
Per the spec, there should only be one. A malformed image containing multiple VP8X chunks can cause unexpected memory usage, since DecodeConfig will only parse the first chunk, which contains the canvas size, but a subsequent chunk can indicate a significantly larger canvas, which we will then try to allocate a buffer for. Change-Id: I240ae76162f4293f6e6991020d18d4d3270cb9b6 Reviewed-on: https://go-review.googlesource.com/c/image/+/551416 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Damien Neil <[email protected]> Auto-Submit: Roland Shoemaker <[email protected]>
1 parent 445ab0e commit 9e190ae

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

webp/decode.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func decode(r io.Reader, configOnly bool) (image.Image, image.Config, error) {
3939
alpha []byte
4040
alphaStride int
4141
wantAlpha bool
42+
seenVP8X bool
4243
widthMinusOne uint32
4344
heightMinusOne uint32
4445
buf [10]byte
@@ -113,6 +114,10 @@ func decode(r io.Reader, configOnly bool) (image.Image, image.Config, error) {
113114
return m, image.Config{}, err
114115

115116
case fccVP8X:
117+
if seenVP8X {
118+
return nil, image.Config{}, errInvalidFormat
119+
}
120+
seenVP8X = true
116121
if chunkLen != 10 {
117122
return nil, image.Config{}, errInvalidFormat
118123
}

webp/decode_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ func TestDecodePartitionTooLarge(t *testing.T) {
271271
}
272272
}
273273

274+
func TestDuplicateVP8X(t *testing.T) {
275+
data := []byte{'R', 'I', 'F', 'F', 49, 0, 0, 0, 'W', 'E', 'B', 'P', 'V', 'P', '8', 'X', 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'V', 'P', '8', 'X', 10, 0, 0, 0, 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0}
276+
_, err := Decode(bytes.NewReader(data))
277+
if err != errInvalidFormat {
278+
t.Fatalf("unexpected error: want %q, got %q", errInvalidFormat, err)
279+
}
280+
}
281+
274282
func benchmarkDecode(b *testing.B, filename string) {
275283
data, err := ioutil.ReadFile("../testdata/blue-purple-pink-large." + filename + ".webp")
276284
if err != nil {

0 commit comments

Comments
 (0)