-
Notifications
You must be signed in to change notification settings - Fork 18k
x/image/bmp: unsupported BMP image #27767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
the implement of bmp reader Package golang.org/x/image/bmp shows that bitmap info header size is fixed to 40, while the header size can set by file header. func decodeConfig(r io.Reader) (config image.Config, bitsPerPixel int, topDown bool, err error) {
// We only support those BMP images that are a BITMAPFILEHEADER
// immediately followed by a BITMAPINFOHEADER.
const (
fileHeaderLen = 14
infoHeaderLen = 40
)
var b [1024]byte
if _, err := io.ReadFull(r, b[:fileHeaderLen+infoHeaderLen]); err != nil {
return image.Config{}, 0, false, err
}
if string(b[:2]) != "BM" {
return image.Config{}, 0, false, errors.New("bmp: invalid format")
}
offset := readUint32(b[10:14])
if readUint32(b[14:18]) != infoHeaderLen {
return image.Config{}, 0, false, ErrUnsupported
} so, maybe we can implement the reader like this func decodeConfig(r io.Reader) (config image.Config, bitsPerPixel int, topDown bool, err error) {
// We only support those BMP images that are a BITMAPFILEHEADER
// immediately followed by a BITMAPINFOHEADER.
const (
fileHeaderLen = 14
)
var infoHeaderLen uint32 = 40 // infoHeaderLen can be a variable
var b [1024]byte
if _, err := io.ReadFull(r, b[:fileHeaderLen+infoHeaderLen]); err != nil {
return image.Config{}, 0, false, err
}
if string(b[:2]) != "BM" {
return image.Config{}, 0, false, errors.New("bmp: invalid format")
}
offset := readUint32(b[10:14])
infoHeaderLen = readUint32(b[14:18]) // set infoHeaderLen from file header other than force compare with 40 |
CC @nigeltao |
Yeah, x/image/bmp needs to speak more versions of the BMP file format. I don't have a lot of spare time to look at this soon, but if anybody else wants to have a crack, here's a couple of spec-like documents: http://www.digicamsoft.com/bmp/bmp.html Translating from Win32 to Go types: |
Thanks, I 'll give a try. |
Change https://golang.org/cl/141799 mentions this issue: |
@yorelog Any progress? You haven't assigned yourself. If you are not actively working on it, I might give it a try, too ;-) |
@mlesniak try it please . I don’t have spare time this days . But it seems someone else have this issue fixed . |
Hmmm, did not found anything on this. Do you have any existing issue where the fix is described? |
|
Decode BITMAPV4INFOHEADER and BITMAPV5INFOHEADER in addition to BITMAPINFOHEADER and check if any of their features are used. If this is not the case, the bmp can be decoded as if it had the BITMAPINFOHEADER. Otherwise an ErrUnsupported is returned. The colormap.bmp and yellow_rose-small-v5.bmp files were generated using imagemagick using the following conversions: convert video-001.bmp -depth 8 -palette colormap.bmp convert yellow_rose-small.bmp -format BMP5 yellow_rose-small-v5.bmp The corresponding png files were created using imagemagick convert without any arguments. Fixes golang/go#27767 Change-Id: I5c0138b231c68132d39a29c71b61faa546921511 Reviewed-on: https://go-review.googlesource.com/c/141799 Reviewed-by: Nigel Tao <nigeltao@golang.org> Run-TryBot: Nigel Tao <nigeltao@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Decode BITMAPV4INFOHEADER and BITMAPV5INFOHEADER in addition to BITMAPINFOHEADER and check if any of their features are used. If this is not the case, the bmp can be decoded as if it had the BITMAPINFOHEADER. Otherwise an ErrUnsupported is returned. The colormap.bmp and yellow_rose-small-v5.bmp files were generated using imagemagick using the following conversions: convert video-001.bmp -depth 8 -palette colormap.bmp convert yellow_rose-small.bmp -format BMP5 yellow_rose-small-v5.bmp The corresponding png files were created using imagemagick convert without any arguments. Fixes golang/go#27767 Change-Id: I5c0138b231c68132d39a29c71b61faa546921511 Reviewed-on: https://go-review.googlesource.com/c/141799 Reviewed-by: Nigel Tao <nigeltao@golang.org> Run-TryBot: Nigel Tao <nigeltao@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Decode BITMAPV4INFOHEADER and BITMAPV5INFOHEADER in addition to BITMAPINFOHEADER and check if any of their features are used. If this is not the case, the bmp can be decoded as if it had the BITMAPINFOHEADER. Otherwise an ErrUnsupported is returned. The colormap.bmp and yellow_rose-small-v5.bmp files were generated using imagemagick using the following conversions: convert video-001.bmp -depth 8 -palette colormap.bmp convert yellow_rose-small.bmp -format BMP5 yellow_rose-small-v5.bmp The corresponding png files were created using imagemagick convert without any arguments. Fixes golang/go#27767 Change-Id: I5c0138b231c68132d39a29c71b61faa546921511 Reviewed-on: https://go-review.googlesource.com/c/141799 Reviewed-by: Nigel Tao <nigeltao@golang.org> Run-TryBot: Nigel Tao <nigeltao@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Decode BITMAPV4INFOHEADER and BITMAPV5INFOHEADER in addition to BITMAPINFOHEADER and check if any of their features are used. If this is not the case, the bmp can be decoded as if it had the BITMAPINFOHEADER. Otherwise an ErrUnsupported is returned. The colormap.bmp and yellow_rose-small-v5.bmp files were generated using imagemagick using the following conversions: convert video-001.bmp -depth 8 -palette colormap.bmp convert yellow_rose-small.bmp -format BMP5 yellow_rose-small-v5.bmp The corresponding png files were created using imagemagick convert without any arguments. Fixes golang/go#27767 Change-Id: I5c0138b231c68132d39a29c71b61faa546921511 Reviewed-on: https://go-review.googlesource.com/c/141799 Reviewed-by: Nigel Tao <nigeltao@golang.org> Run-TryBot: Nigel Tao <nigeltao@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Decode BITMAPV4INFOHEADER and BITMAPV5INFOHEADER in addition to BITMAPINFOHEADER and check if any of their features are used. If this is not the case, the bmp can be decoded as if it had the BITMAPINFOHEADER. Otherwise an ErrUnsupported is returned. The colormap.bmp and yellow_rose-small-v5.bmp files were generated using imagemagick using the following conversions: convert video-001.bmp -depth 8 -palette colormap.bmp convert yellow_rose-small.bmp -format BMP5 yellow_rose-small-v5.bmp The corresponding png files were created using imagemagick convert without any arguments. Fixes golang/go#27767 Change-Id: I5c0138b231c68132d39a29c71b61faa546921511 Reviewed-on: https://go-review.googlesource.com/c/141799 Reviewed-by: Nigel Tao <nigeltao@golang.org> Run-TryBot: Nigel Tao <nigeltao@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Decode BITMAPV4INFOHEADER and BITMAPV5INFOHEADER in addition to BITMAPINFOHEADER and check if any of their features are used. If this is not the case, the bmp can be decoded as if it had the BITMAPINFOHEADER. Otherwise an ErrUnsupported is returned. The colormap.bmp and yellow_rose-small-v5.bmp files were generated using imagemagick using the following conversions: convert video-001.bmp -depth 8 -palette colormap.bmp convert yellow_rose-small.bmp -format BMP5 yellow_rose-small-v5.bmp The corresponding png files were created using imagemagick convert without any arguments. Fixes golang/go#27767 Change-Id: I5c0138b231c68132d39a29c71b61faa546921511 Reviewed-on: https://go-review.googlesource.com/c/141799 Reviewed-by: Nigel Tao <nigeltao@golang.org> Run-TryBot: Nigel Tao <nigeltao@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Decode BITMAPV4INFOHEADER and BITMAPV5INFOHEADER in addition to BITMAPINFOHEADER and check if any of their features are used. If this is not the case, the bmp can be decoded as if it had the BITMAPINFOHEADER. Otherwise an ErrUnsupported is returned. The colormap.bmp and yellow_rose-small-v5.bmp files were generated using imagemagick using the following conversions: convert video-001.bmp -depth 8 -palette colormap.bmp convert yellow_rose-small.bmp -format BMP5 yellow_rose-small-v5.bmp The corresponding png files were created using imagemagick convert without any arguments. Fixes golang/go#27767 Change-Id: I5c0138b231c68132d39a29c71b61faa546921511 Reviewed-on: https://go-review.googlesource.com/c/141799 Reviewed-by: Nigel Tao <nigeltao@golang.org> Run-TryBot: Nigel Tao <nigeltao@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Decode BITMAPV4INFOHEADER and BITMAPV5INFOHEADER in addition to BITMAPINFOHEADER and check if any of their features are used. If this is not the case, the bmp can be decoded as if it had the BITMAPINFOHEADER. Otherwise an ErrUnsupported is returned. The colormap.bmp and yellow_rose-small-v5.bmp files were generated using imagemagick using the following conversions: convert video-001.bmp -depth 8 -palette colormap.bmp convert yellow_rose-small.bmp -format BMP5 yellow_rose-small-v5.bmp The corresponding png files were created using imagemagick convert without any arguments. Fixes golang/go#27767 Change-Id: I5c0138b231c68132d39a29c71b61faa546921511 Reviewed-on: https://go-review.googlesource.com/c/141799 Reviewed-by: Nigel Tao <nigeltao@golang.org> Run-TryBot: Nigel Tao <nigeltao@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Decode BITMAPV4INFOHEADER and BITMAPV5INFOHEADER in addition to BITMAPINFOHEADER and check if any of their features are used. If this is not the case, the bmp can be decoded as if it had the BITMAPINFOHEADER. Otherwise an ErrUnsupported is returned. The colormap.bmp and yellow_rose-small-v5.bmp files were generated using imagemagick using the following conversions: convert video-001.bmp -depth 8 -palette colormap.bmp convert yellow_rose-small.bmp -format BMP5 yellow_rose-small-v5.bmp The corresponding png files were created using imagemagick convert without any arguments. Fixes golang/go#27767 Change-Id: I5c0138b231c68132d39a29c71b61faa546921511 Reviewed-on: https://go-review.googlesource.com/c/141799 Reviewed-by: Nigel Tao <nigeltao@golang.org> Run-TryBot: Nigel Tao <nigeltao@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.11 linux/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?GOOS="linux"
GOARCH="amd64"
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
What did you expect to see?
exit code is 0
What did you see instead?
2018/09/20 10:45:39 bmp: unsupported BMP image
exit status 1
Because github does not support bmp, package bmp image files into compressed files.
desktop.bmp.tar.gz
The text was updated successfully, but these errors were encountered: