diff options
Diffstat (limited to 'vendor/golang.org/x/image/bmp/reader.go')
-rw-r--r-- | vendor/golang.org/x/image/bmp/reader.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/vendor/golang.org/x/image/bmp/reader.go b/vendor/golang.org/x/image/bmp/reader.go index e165c2e39..1939c1120 100644 --- a/vendor/golang.org/x/image/bmp/reader.go +++ b/vendor/golang.org/x/image/bmp/reader.go @@ -191,14 +191,22 @@ func decodeConfig(r io.Reader) (config image.Config, bitsPerPixel int, topDown b } switch bpp { case 8: - if offset != fileHeaderLen+infoLen+256*4 { + colorUsed := readUint32(b[46:50]) + // If colorUsed is 0, it is set to the maximum number of colors for the given bpp, which is 2^bpp. + if colorUsed == 0 { + colorUsed = 256 + } else if colorUsed > 256 { return image.Config{}, 0, false, false, ErrUnsupported } - _, err = io.ReadFull(r, b[:256*4]) + + if offset != fileHeaderLen+infoLen+colorUsed*4 { + return image.Config{}, 0, false, false, ErrUnsupported + } + _, err = io.ReadFull(r, b[:colorUsed*4]) if err != nil { return image.Config{}, 0, false, false, err } - pcm := make(color.Palette, 256) + pcm := make(color.Palette, colorUsed) for i := range pcm { // BMP images are stored in BGR order rather than RGB order. // Every 4th byte is padding. |