diff options
Diffstat (limited to 'vendor/golang.org')
-rw-r--r-- | vendor/golang.org/x/image/bmp/reader.go | 14 | ||||
-rw-r--r-- | vendor/golang.org/x/image/tiff/reader.go | 33 | ||||
-rw-r--r-- | vendor/golang.org/x/text/language/match.go | 2 |
3 files changed, 40 insertions, 9 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. diff --git a/vendor/golang.org/x/image/tiff/reader.go b/vendor/golang.org/x/image/tiff/reader.go index 45cc056f4..f31569b6d 100644 --- a/vendor/golang.org/x/image/tiff/reader.go +++ b/vendor/golang.org/x/image/tiff/reader.go @@ -8,13 +8,13 @@ package tiff // import "golang.org/x/image/tiff" import ( + "bytes" "compress/zlib" "encoding/binary" "fmt" "image" "image/color" "io" - "io/ioutil" "math" "golang.org/x/image/ccitt" @@ -579,6 +579,11 @@ func newDecoder(r io.Reader) (*decoder, error) { default: return nil, UnsupportedError("color model") } + if d.firstVal(tPhotometricInterpretation) != pRGB { + if len(d.features[tBitsPerSample]) != 1 { + return nil, UnsupportedError("extra samples") + } + } return d, nil } @@ -629,6 +634,13 @@ func Decode(r io.Reader) (img image.Image, err error) { blockWidth = int(d.firstVal(tTileWidth)) blockHeight = int(d.firstVal(tTileLength)) + // The specification says that tile widths and lengths must be a multiple of 16. + // We currently permit invalid sizes, but reject anything too small to limit the + // amount of work a malicious input can force us to perform. + if blockWidth < 8 || blockHeight < 8 { + return nil, FormatError("tile size is too small") + } + if blockWidth != 0 { blocksAcross = (d.config.Width + blockWidth - 1) / blockWidth } @@ -681,6 +693,11 @@ func Decode(r io.Reader) (img image.Image, err error) { } } + if blocksAcross == 0 || blocksDown == 0 { + return + } + // Maximum data per pixel is 8 bytes (RGBA64). + blockMaxDataSize := int64(blockWidth) * int64(blockHeight) * 8 for i := 0; i < blocksAcross; i++ { blkW := blockWidth if !blockPadding && i == blocksAcross-1 && d.config.Width%blockWidth != 0 { @@ -708,15 +725,15 @@ func Decode(r io.Reader) (img image.Image, err error) { inv := d.firstVal(tPhotometricInterpretation) == pWhiteIsZero order := ccittFillOrder(d.firstVal(tFillOrder)) r := ccitt.NewReader(io.NewSectionReader(d.r, offset, n), order, ccitt.Group3, blkW, blkH, &ccitt.Options{Invert: inv, Align: false}) - d.buf, err = ioutil.ReadAll(r) + d.buf, err = readBuf(r, d.buf, blockMaxDataSize) case cG4: inv := d.firstVal(tPhotometricInterpretation) == pWhiteIsZero order := ccittFillOrder(d.firstVal(tFillOrder)) r := ccitt.NewReader(io.NewSectionReader(d.r, offset, n), order, ccitt.Group4, blkW, blkH, &ccitt.Options{Invert: inv, Align: false}) - d.buf, err = ioutil.ReadAll(r) + d.buf, err = readBuf(r, d.buf, blockMaxDataSize) case cLZW: r := lzw.NewReader(io.NewSectionReader(d.r, offset, n), lzw.MSB, 8) - d.buf, err = ioutil.ReadAll(r) + d.buf, err = readBuf(r, d.buf, blockMaxDataSize) r.Close() case cDeflate, cDeflateOld: var r io.ReadCloser @@ -724,7 +741,7 @@ func Decode(r io.Reader) (img image.Image, err error) { if err != nil { return nil, err } - d.buf, err = ioutil.ReadAll(r) + d.buf, err = readBuf(r, d.buf, blockMaxDataSize) r.Close() case cPackBits: d.buf, err = unpackBits(io.NewSectionReader(d.r, offset, n)) @@ -748,6 +765,12 @@ func Decode(r io.Reader) (img image.Image, err error) { return } +func readBuf(r io.Reader, buf []byte, lim int64) ([]byte, error) { + b := bytes.NewBuffer(buf[:0]) + _, err := b.ReadFrom(io.LimitReader(r, lim)) + return b.Bytes(), err +} + func init() { image.RegisterFormat("tiff", leHeader, Decode, DecodeConfig) image.RegisterFormat("tiff", beHeader, Decode, DecodeConfig) diff --git a/vendor/golang.org/x/text/language/match.go b/vendor/golang.org/x/text/language/match.go index ee45f4947..1153baf29 100644 --- a/vendor/golang.org/x/text/language/match.go +++ b/vendor/golang.org/x/text/language/match.go @@ -434,7 +434,7 @@ func newMatcher(supported []Tag, options []MatchOption) *matcher { // (their canonicalization simply substitutes a different language code, but // nothing else), the match confidence is Exact, otherwise it is High. for i, lm := range language.AliasMap { - // If deprecated codes match and there is no fiddling with the script or + // If deprecated codes match and there is no fiddling with the script // or region, we consider it an exact match. conf := Exact if language.AliasTypes[i] != language.Macro { |