// Copyright 2011 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package tiffimport ()type byteReader interface {io.Readerio.ByteReader}// unpackBits decodes the PackBits-compressed data in src and returns the// uncompressed data. The output size is limited to lim bytes to prevent// decompression bombs.//// The PackBits compression format is described in section 9 (p. 42)// of the TIFF spec.func unpackBits( io.Reader, int64) ([]byte, error) { := make([]byte, 128) := make([]byte, 0, 1024) , := .(byteReader)if ! { = bufio.NewReader() }for { , := .ReadByte()if != nil {if == io.EOF {return , nil }returnnil, } := int(int8())switch {case >= 0: , := io.ReadFull(, [:+1])if != nil {returnnil, } = append(, [:]...)case == -128:// No-op.default:if , = .ReadByte(); != nil {returnnil, }for := 0; < 1-; ++ { [] = } = append(, [:1-]...) }ifint64(len()) > {returnnil, FormatError("PackBits: decompressed data too large") } }}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.