Skip to content

Commit

Permalink
Merge pull request #8 from rfuzz/master
Browse files Browse the repository at this point in the history
Add Multiplication Overflow Check
  • Loading branch information
mdsteele authored Oct 7, 2024
2 parents d1ae9e4 + 98cd3a0 commit 902f285
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl IconImage {
rgba.push(value);
rgba.push(value);
rgba.push(value);
rgba.push(std::u8::MAX);
rgba.push(u8::MAX);
}
rgba
}
Expand Down Expand Up @@ -292,7 +292,11 @@ impl IconImage {

// Read in the color data, which is stored row by row, starting from
// the *bottom* row:
let num_pixels = (width * height) as usize;

let num_pixels = match width.checked_mul(height) {
Some(num) => num as usize,
None => invalid_data!("Width * Height is too large"),
};
let mut rgba = vec![u8::MAX; num_pixels * 4];
let row_data_size = (width * (bits_per_pixel as u32) + 7) / 8;
let row_padding_size = ((row_data_size + 3) / 4) * 4 - row_data_size;
Expand Down

0 comments on commit 902f285

Please sign in to comment.