From 50ef03e3199e86ac3c8db6f51ab045eaeb15b835 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 18 Oct 2023 14:13:25 +0800 Subject: [PATCH] alternate XOR pattern for busy-bar this it to avoid abusing the primitive to create inverted text (for secure UI elements only). It does degrade from the aesthetics of a busy bar but it is a computationally efficient way to patch around the concern. --- services/graphics-server/Cargo.toml | 2 +- services/graphics-server/src/op.rs | 6 +++++- services/graphics-server/src/testing.rs | 14 ++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/services/graphics-server/Cargo.toml b/services/graphics-server/Cargo.toml index 4df01a221..abee7d55d 100644 --- a/services/graphics-server/Cargo.toml +++ b/services/graphics-server/Cargo.toml @@ -34,4 +34,4 @@ debugprint = [] braille = [] gfx-testing = [] ditherpunk = [] -default = [] +default = ["gfx-testing"] diff --git a/services/graphics-server/src/op.rs b/services/graphics-server/src/op.rs index f3162338e..873620b82 100644 --- a/services/graphics-server/src/op.rs +++ b/services/graphics-server/src/op.rs @@ -275,7 +275,11 @@ pub fn rectangle(fb: &mut LcdFB, rect: Rectangle, clip: Option, xor: // This is to make it annoying for someone using an XOR rectangle to synthesize inverted // text on an otherwise untrusted dialog box (I suspect it's not impossible, but introduces // a likelihood of drawing artifacts especially across translations and font size selections). - xor_pixel(fb, pixel.0.x, pixel.0.y); + if pixel.0.y % 20 < 10 { + xor_pixel(fb, pixel.0.x, pixel.0.y); + } else { + // don't allow XOR on some pixels to avoid this being used as a primitive to synthesize secure boxes + } } else { log::warn!("invalid xor rect width"); put_pixel(fb, pixel.0.x, pixel.0.y, pixel.1); diff --git a/services/graphics-server/src/testing.rs b/services/graphics-server/src/testing.rs index 67f02288f..716ef9bfe 100644 --- a/services/graphics-server/src/testing.rs +++ b/services/graphics-server/src/testing.rs @@ -62,10 +62,16 @@ pub fn tests() { tv.insertion = None; tv.draw_border = false; tv.busy_animation_state = Some(0); - for _ in 0..4800 { - gfx.draw_textview(&mut tv).unwrap(); - gfx.flush().unwrap(); - ticktimer.sleep_ms(100).unwrap(); + for y in 0..30 { + gfx.draw_rectangle(checkbound).unwrap(); + tv.bounds_hint = TextBounds::BoundingBox(Rectangle::new_coords( + 10, 10 + y, 240, 30 + y + )); + for _ in 0..5 { + gfx.draw_textview(&mut tv).unwrap(); + gfx.flush().unwrap(); + ticktimer.sleep_ms(100).unwrap(); + } } } Some(TestType::BoundingBox) => {