From 1ee2062c1b64ecfda0af49cb0f721573aad7dea4 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 6 Aug 2020 14:28:22 -0500 Subject: [PATCH] framebufferio: Check early if framebuffer is big enough --- shared-module/framebufferio/FramebufferDisplay.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/shared-module/framebufferio/FramebufferDisplay.c b/shared-module/framebufferio/FramebufferDisplay.c index e16777b83b..230dd6991d 100644 --- a/shared-module/framebufferio/FramebufferDisplay.c +++ b/shared-module/framebufferio/FramebufferDisplay.c @@ -79,6 +79,13 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu if (self->row_stride == 0) { self->row_stride = self->core.width * self->core.colorspace.depth/8; } + + self->framebuffer_protocol->get_bufinfo(self->framebuffer, &self->bufinfo); + size_t framebuffer_size = self->first_pixel_offset + self->row_stride * self->core.height; + if (self->bufinfo.len < framebuffer_size) { + mp_raise_IndexError_varg(translate("Framebuffer requires %d bytes"), framebuffer_size); + } + self->first_manual_refresh = !auto_refresh; self->native_frames_per_second = self->framebuffer_protocol->get_native_frames_per_second(self->framebuffer);