Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.20.5 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home//.cache/go-build" GOENV="/home//.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home//go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home//go" GOPRIVATE="" GOPROXY="direct" GOROOT="/usr/lib/golang" GOSUMDB="off" GOTMPDIR="" GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.20.5" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" CGO_CFLAGS="-O2 -g" CGO_CPPFLAGS="" CGO_CXXFLAGS="-O2 -g" CGO_FFLAGS="-O2 -g" CGO_LDFLAGS="-O2 -g" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1874621086=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I got bmp: unsupported BMP image
when I tried to Decode the following image.
- colormap-251.bmp
- colormap-251.bmp.zip
- 8-bit format, 251 color palette
- I made it by editing testdata/colormap.bmp with GIMP.
Sample code:
package main
import (
"os"
"golang.org/x/image/bmp"
)
func main() {
f, err := os.Open("colormap-251.bmp")
if err != nil {
panic(err)
}
defer f.Close()
_, err = bmp.Decode(f)
if err != nil {
panic(err)
}
}
What did you expect to see?
Decode success
What did you see instead?
$ go run .
panic: bmp: unsupported BMP image
...
Additional information
Current implementation of reader.go
assumes that the number of palette is 256. Therefore, bmp: unsupported BMP image
occurs when the number of palette is not 256.
I think that the number of palette should depend on biClrUsed
of BITMAPINFOHEADER
instead of fixing it to 256. Note that if biClrUsed
is 0, the number of palette is 2 to the power of bit per pixel (e.g. 256 colors for 8-bit format, 16 colors for 4-bit format).
I will modify reader.go
to support 8-bit format with up to 256 color palette.
References: