drivers/gop: Skip modes with invalid pitch values
diff --git a/common/drivers/gop.c b/common/drivers/gop.c
index 2f2ac0f7..acbf6399 100644
--- a/common/drivers/gop.c
+++ b/common/drivers/gop.c
@@ -102,6 +102,16 @@ static bool mode_to_fb_info(struct fb_info *ret, EFI_GRAPHICS_OUTPUT_PROTOCOL *g
ret->framebuffer_width = mode_info->HorizontalResolution;
ret->framebuffer_height = mode_info->VerticalResolution;
+ uint64_t bytes_per_pixel = ret->framebuffer_bpp / 8;
+ if (bytes_per_pixel == 0
+ || ret->framebuffer_pitch % bytes_per_pixel != 0
+ || ret->framebuffer_pitch < ret->framebuffer_width * bytes_per_pixel) {
+ printv("gop: Mode %u has invalid pitch %u (width=%u, bpp=%u), skipping.\n",
+ (uint32_t)mode, (uint32_t)ret->framebuffer_pitch,
+ (uint32_t)ret->framebuffer_width, (uint32_t)ret->framebuffer_bpp);
+ return false;
+ }
+
return true;
}
