Skip to content
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

x/image/bmp: unsupported BMP image #27767

Closed
electricface opened this issue Sep 20, 2018 · 9 comments
Closed

x/image/bmp: unsupported BMP image #27767

electricface opened this issue Sep 20, 2018 · 9 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@electricface
Copy link

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.

package main

import (
	"image"
	"log"
	"os"

	_ "golang.org/x/image/bmp"
)

func main() {
	f, err := os.Open("/path/to/desktop.bmp")
	if err != nil {
		log.Fatal(err)
	}
	img, str, err := image.Decode(f)
	if err != nil {
		log.Fatal(err)
	}
	log.Println(img, str)
}

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

@gopherbot gopherbot added this to the Unreleased milestone Sep 20, 2018
@yorelog
Copy link

yorelog commented Sep 21, 2018

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 

@bcmills
Copy link
Contributor

bcmills commented Sep 22, 2018

CC @nigeltao

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 22, 2018
@bradfitz bradfitz changed the title x/image/bmp bmp: unsupported BMP image x/image/bmp: unsupported BMP image Sep 25, 2018
@nigeltao
Copy link
Contributor

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
https://www.fileformat.info/format/bmp/egff.htm

Translating from Win32 to Go types:
SHORT = int16
LONG = int32
BYTE = uint8
WORD = uint16
DWORD = uint32

@yorelog
Copy link

yorelog commented Sep 26, 2018

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
https://www.fileformat.info/format/bmp/egff.htm

Translating from Win32 to Go types:
SHORT = int16
LONG = int32
BYTE = uint8
WORD = uint16
DWORD = uint32

Thanks, I 'll give a try.

@bcmills bcmills added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Sep 26, 2018
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 26, 2018
@gopherbot
Copy link

Change https://golang.org/cl/141799 mentions this issue: image/bmp: support v4 and v5 info header versions

@mlesniak
Copy link

@yorelog Any progress? You haven't assigned yourself. If you are not actively working on it, I might give it a try, too ;-)

@yorelog
Copy link

yorelog commented Oct 19, 2018

@mlesniak try it please . I don’t have spare time this days . But it seems someone else have this issue fixed .
Also, you can compare this with Pillow package (python ) to improve it .
Sorry for the inactive

@mlesniak
Copy link

@yorelog

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?

@yorelog
Copy link

yorelog commented Oct 20, 2018

Change https://golang.org/cl/141799 mentions this issue: image/bmp: support v4 and v5 info header versions

@mlesniak

@golang golang locked and limited conversation to collaborators Oct 23, 2019
mrhyperbit23z0d added a commit to mrhyperbit23z0d/bhegde8 that referenced this issue Jun 6, 2022
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>
GalaxyForcew added a commit to GalaxyForcew/A1bisshy that referenced this issue Jun 6, 2022
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>
yi-ge3 added a commit to yi-ge3/wislie that referenced this issue Jun 6, 2022
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>
balloontmz6 added a commit to balloontmz6/Likewise42l that referenced this issue Jun 6, 2022
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>
snapbakkhfbav added a commit to snapbakkhfbav/SayedBaladohr that referenced this issue Oct 6, 2022
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>
MiderWong5ddop added a commit to MiderWong5ddop/sidie88f that referenced this issue Oct 7, 2022
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>
rorypeckwnt4v added a commit to rorypeckwnt4v/LearnByBhanuPrataph that referenced this issue Oct 7, 2022
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>
egorovcharenko9 added a commit to egorovcharenko9/RiceBIOC470z that referenced this issue Oct 7, 2022
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>
RafayGhafoorf added a commit to RafayGhafoorf/dustinsand8 that referenced this issue Oct 7, 2022
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>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants