mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 16:47:28 +01:00
Fix std/bmp checking bits_per_pixel too early
This commit is contained in:
1 parent
0ccdece50a
commit
6695e4aae8
2 files changed
+34
-34
No files matched your search
+17
-17
@@ -106,23 +106,6 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
}
|
||||
this.padding -= this.bitmap_info_len
|
||||
|
||||
if this.bitmap_info_len == 40 {
|
||||
if this.bits_per_pixel >= 16 {
|
||||
// It's poorly documented, but "length 40" data can be silently
|
||||
// augmented with RGB or RGBA channel_masks (12 or 16 bytes).
|
||||
if this.padding >= 16 {
|
||||
this.bitmap_info_len = 56
|
||||
this.padding -= 16
|
||||
} else if this.padding >= 12 {
|
||||
this.bitmap_info_len = 52
|
||||
this.padding -= 12
|
||||
}
|
||||
}
|
||||
} else if (this.bitmap_info_len <> 52) and (this.bitmap_info_len <> 56) and
|
||||
(this.bitmap_info_len <> 108) and (this.bitmap_info_len <> 124) {
|
||||
return "#unsupported BMP file"
|
||||
}
|
||||
|
||||
width = args.src.read_u32le?()
|
||||
if width >= 0x8000_0000 {
|
||||
return "#bad header"
|
||||
@@ -164,6 +147,23 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
// the version 3 BITMAPINFOHEADER (whose total size is 40).
|
||||
args.src.skip_u32?(n: 40 - 20)
|
||||
|
||||
if this.bitmap_info_len == 40 {
|
||||
if this.bits_per_pixel >= 16 {
|
||||
// It's poorly documented, but "length 40" data can be silently
|
||||
// augmented with RGB or RGBA channel_masks (12 or 16 bytes).
|
||||
if this.padding >= 16 {
|
||||
this.bitmap_info_len = 56
|
||||
this.padding -= 16
|
||||
} else if this.padding >= 12 {
|
||||
this.bitmap_info_len = 52
|
||||
this.padding -= 12
|
||||
}
|
||||
}
|
||||
} else if (this.bitmap_info_len <> 52) and (this.bitmap_info_len <> 56) and
|
||||
(this.bitmap_info_len <> 108) and (this.bitmap_info_len <> 124) {
|
||||
return "#unsupported BMP file"
|
||||
}
|
||||
|
||||
// Treat 6 (ALPHABITFIELDS) the same as 3 (BITFIELDS).
|
||||
if this.compression == 6 {
|
||||
this.compression = 3
|
||||
|
||||
Reference in new issue
Block a user