Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
fix: avoid overflowing multiplications in draw_buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin-Niederman committed Feb 15, 2024
1 parent e04bb07 commit fcfc612
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/pros/src/devices/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ impl Screen {
.into_iter()
.map(|i| i.into_rgb().into())
.collect::<Vec<_>>();
let expected_size = ((x1 - x0) * (y1 - y0)) as usize;
// Convert the coordinates to u32 to avoid overflows when multiplying.
let expected_size = ((x1 - x0) as u32 * (y1 - y0) as u32) as usize;
if raw_buf.len() != expected_size {
return Err(ScreenError::CopyBufferWrongSize {
buffer_size: raw_buf.len(),
Expand Down

0 comments on commit fcfc612

Please sign in to comment.