From 0c2303d789ef0c39051ea61e4f64ff7a082d18b9 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Fri, 24 Oct 2025 19:54:28 -0700 Subject: [PATCH] fix(framebuffer): add proper bounds checking for accessing a pixel --- src/utils/framebuffer.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils/framebuffer.rs b/src/utils/framebuffer.rs index 6b3afc4..084df36 100644 --- a/src/utils/framebuffer.rs +++ b/src/utils/framebuffer.rs @@ -31,6 +31,11 @@ impl Framebuffer { /// Mutably acquires a pixel of the framebuffer at the specified `x` and `y` coordinate. pub fn pixel(&mut self, x: usize, y: usize) -> Option<&mut BltPixel> { + // Verify that the coordinates are within the bounds of the framebuffer. + if x >= self.width || y >= self.height { + return None; + } + // Calculate the index of the pixel safely, returning None if it overflows. let index = y.checked_mul(self.width)?.checked_add(x)?; // Return the pixel at the index. If the index is out of bounds, this will return None.