Skip to content

Commit

Permalink
webp: fix panic in case of invalid chunkID
Browse files Browse the repository at this point in the history
At the time of decoding webp file, if chunkID is not one of
{'ALPH', 'VP8', 'VP8L', 'VP8X'} return errInvalidFormat

Fixes golang/go#10384

Change-Id: I167909b5ddef174d161f806297a08fac6aabcf19
Reviewed-on: https://go-review.googlesource.com/9839
Reviewed-by: Nigel Tao <[email protected]>
  • Loading branch information
balloontmz6 committed Feb 10, 2022
1 parent 8409dd7 commit 034113b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 3 additions & 4 deletions riff/riff.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@ func (z *Reader) Next() (chunkID FourCC, chunkLen uint32, chunkData io.Reader, e
return FourCC{}, 0, nil, z.err
}
chunkID = FourCC{z.buf[0], z.buf[1], z.buf[2], z.buf[3]}
chunkLen = u32(z.buf[4:])
z.chunkLen = chunkLen
z.padded = chunkLen&1 == 1
z.chunkLen = u32(z.buf[4:])
z.padded = z.chunkLen&1 == 1
z.chunkReader = &chunkReader{z}
return chunkID, chunkLen, z.chunkReader, nil
return chunkID, z.chunkLen, z.chunkReader, nil
}

type chunkReader struct {
Expand Down
3 changes: 3 additions & 0 deletions webp/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ func decode(r io.Reader, configOnly bool) (image.Image, image.Config, error) {
}, nil
}
wantAlpha = true

default:
return nil, image.Config{}, errInvalidFormat
}
}
}
Expand Down

0 comments on commit 034113b

Please sign in to comment.