Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/codecs/bmp/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,10 @@ impl<R: BufRead + Seek> BmpDecoder<R> {
pub(crate) fn reader(&mut self) -> &mut R {
&mut self.reader
}
#[cfg(feature = "ico")]
pub(crate) fn bit_count(&self) -> u16 {
self.bit_count
}

fn read_file_header(&mut self) -> ImageResult<()> {
if self.no_file_header {
Expand Down
12 changes: 8 additions & 4 deletions src/codecs/ico/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,12 @@ impl<R: BufRead + Seek> ImageDecoder for IcoDecoder<R> {

decoder.read_image_data(buf)?;

// For further processing, use the bits per pixel from the BMP.
// The data in the ICON dir entry is not generally trustworthy, but the data from
// the BMP header just correctly decoded an image. Using the data from the BMP
// header also eliminates any mismatches between the BMP header and the ICON dir entry.
let bit_count = decoder.bit_count();

let r = decoder.reader();
let image_end = r.stream_position()?;
let data_end = self.reader_offset
Expand All @@ -395,7 +401,7 @@ impl<R: BufRead + Seek> ImageDecoder for IcoDecoder<R> {
// 32bpp BMPs already have a native alpha channel, so the
// AND mask is ignored.
// For lower bit depths, read and apply the AND mask.
if self.selected_entry.bits_per_pixel < 32 {
if bit_count < 32 {
let rgba = buf.as_chunks_mut::<4>().0;
let rows = rgba.chunks_exact_mut(width as usize);

Expand Down Expand Up @@ -431,9 +437,7 @@ impl<R: BufRead + Seek> ImageDecoder for IcoDecoder<R> {
} else if data_end == image_end {
// accept images with no mask data
Ok(DecodedImageAttributes::default())
} else if self.spec_strictness == SpecCompliance::Lenient
&& self.selected_entry.bits_per_pixel >= 32
{
} else if self.spec_strictness == SpecCompliance::Lenient && bit_count >= 32 {
// In lenient mode, we accept truncated mask data for 32bpp images
// since they already have an alpha channel and we ignore the AND mask anyway.
Ok(DecodedImageAttributes::default())
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading