From b51959ea772d9f25bb3c8aeb6d0a15bcc1f1d9ef Mon Sep 17 00:00:00 2001 From: aviralgarg05 Date: Thu, 23 Jul 2026 16:00:42 +0530 Subject: [PATCH] games/NXDoom: validate framebuffer pixel format, not just depth. blit_screen() branches purely on pinfo.bpp (16 vs 32) to decide between the RGB565 and RGB32 conversion paths, but bit depth alone doesn't determine pixel layout - multiple incompatible formats share the same depth. i_init_graphics() now checks vinfo.fmt against the one format blit_screen() actually emits for each depth (FB_FMT_RGB16_565 for 16bpp, FB_FMT_RGB32 for 32bpp) and fails loudly via i_error() on any mismatch or unsupported depth, instead of silently misinterpreting the framebuffer's actual pixel layout. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: aviralgarg05 --- games/NXDoom/src/i_video.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/games/NXDoom/src/i_video.c b/games/NXDoom/src/i_video.c index 544c0fe65..b2189339b 100644 --- a/games/NXDoom/src/i_video.c +++ b/games/NXDoom/src/i_video.c @@ -772,6 +772,22 @@ void i_init_graphics(void) i_error("ioctl(FBIOGET_PLANEINFO) failed: %d\n", errno); } + /* Depth alone is not enough: several incompatible pixel layouts use 16 + * or 32 bits. The conversion in blit_screen() emits RGB565 or RGB32. + */ + + if ((g_graphics_state.pinfo.bpp == 16 && + g_graphics_state.vinfo.fmt != FB_FMT_RGB16_565) || + (g_graphics_state.pinfo.bpp == 32 && + g_graphics_state.vinfo.fmt != FB_FMT_RGB32) || + (g_graphics_state.pinfo.bpp != 16 && + g_graphics_state.pinfo.bpp != 32)) + { + i_error("Unsupported framebuffer format: fmt=%u, bpp=%u", + g_graphics_state.vinfo.fmt, + g_graphics_state.pinfo.bpp); + } + /* Initialize frame buffer memory for actual rendering */ g_graphics_state.fbmem =