From c2de5506bc7d22bef91257a0f81b195a4c22fd83 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Fri, 22 Sep 2023 16:49:12 +0200 Subject: [PATCH] fix(core): add boundaries check for icon rendering (framebuffer variant) [no changelog] --- core/embed/rust/src/ui/display/toif.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/core/embed/rust/src/ui/display/toif.rs b/core/embed/rust/src/ui/display/toif.rs index f3a5f8388f..b39059e1c0 100644 --- a/core/embed/rust/src/ui/display/toif.rs +++ b/core/embed/rust/src/ui/display/toif.rs @@ -10,6 +10,7 @@ use crate::{ geometry::{Alignment2D, Offset, Point, Rect}, }, }; +use core::cmp::max; #[cfg(feature = "dma2d")] use crate::{ @@ -74,8 +75,9 @@ pub fn render_toif(toif: &Toif, center: Point, fg_color: Color, bg_color: Color) pub fn render_toif(toif: &Toif, center: Point, fg_color: Color, bg_color: Color) { let r = Rect::from_center_and_size(center, toif.size()); let area = r.translate(get_offset()); + let clamped = area.clamp(constant::screen()).ensure_even_width(); - set_window(area); + set_window(clamped); let mut b1 = BufferLine4bpp::get_cleared(); let mut b2 = BufferLine4bpp::get_cleared(); @@ -85,13 +87,23 @@ pub fn render_toif(toif: &Toif, center: Point, fg_color: Color, bg_color: Color) dma2d_setup_4bpp(fg_color.into(), bg_color.into()); - for y in area.y0..area.y1 { + let x_shift = max(0, clamped.x0 - area.x0); + + for y in area.y0..clamped.y1 { let img_buffer_used = if y % 2 == 0 { &mut b1 } else { &mut b2 }; - unwrap!(ctx.uncompress(&mut (&mut img_buffer_used.buffer)[0..(area.width() / 2) as usize])); + unwrap!(ctx.uncompress(&mut (&mut img_buffer_used.buffer)[..(area.width() / 2) as usize])); - dma2d_wait_for_transfer(); - unsafe { dma2d_start(&img_buffer_used.buffer, area.width()) }; + if y >= clamped.y0 { + dma2d_wait_for_transfer(); + unsafe { + dma2d_start( + &img_buffer_used.buffer + [(x_shift / 2) as usize..((clamped.width() + x_shift) / 2) as usize], + clamped.width(), + ) + }; + } } dma2d_wait_for_transfer();