diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 729e27b3..3dbe3101 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -16386,23 +16386,6 @@ wuffs_bmp__decoder__decode_image_config( goto exit; } self->private_impl.f_padding -= self->private_impl.f_bitmap_info_len; - if (self->private_impl.f_bitmap_info_len == 40) { - if (self->private_impl.f_bits_per_pixel >= 16) { - if (self->private_impl.f_padding >= 16) { - self->private_impl.f_bitmap_info_len = 56; - self->private_impl.f_padding -= 16; - } else if (self->private_impl.f_padding >= 12) { - self->private_impl.f_bitmap_info_len = 52; - self->private_impl.f_padding -= 12; - } - } - } else if ((self->private_impl.f_bitmap_info_len != 52) && - (self->private_impl.f_bitmap_info_len != 56) && - (self->private_impl.f_bitmap_info_len != 108) && - (self->private_impl.f_bitmap_info_len != 124)) { - status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file); - goto exit; - } { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); uint32_t t_3; @@ -16588,6 +16571,23 @@ wuffs_bmp__decoder__decode_image_config( goto suspend; } iop_a_src += self->private_data.s_decode_image_config[0].scratch; + if (self->private_impl.f_bitmap_info_len == 40) { + if (self->private_impl.f_bits_per_pixel >= 16) { + if (self->private_impl.f_padding >= 16) { + self->private_impl.f_bitmap_info_len = 56; + self->private_impl.f_padding -= 16; + } else if (self->private_impl.f_padding >= 12) { + self->private_impl.f_bitmap_info_len = 52; + self->private_impl.f_padding -= 12; + } + } + } else if ((self->private_impl.f_bitmap_info_len != 52) && + (self->private_impl.f_bitmap_info_len != 56) && + (self->private_impl.f_bitmap_info_len != 108) && + (self->private_impl.f_bitmap_info_len != 124)) { + status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file); + goto exit; + } if (self->private_impl.f_compression == 6) { self->private_impl.f_compression = 3; } diff --git a/std/bmp/decode_bmp.wuffs b/std/bmp/decode_bmp.wuffs index 5c374839..59355f74 100644 --- a/std/bmp/decode_bmp.wuffs +++ b/std/bmp/decode_bmp.wuffs @@ -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