From 04788e15af6878c220602d2248b2b8f5182e96a0 Mon Sep 17 00:00:00 2001 From: Rangi Date: Sat, 1 May 2021 22:33:54 -0400 Subject: [PATCH] Fix a potential out-of-bounds array access in RGBGFX This was caught by ASAN for pokered's gfx/battle/minimize.png. --- src/gfx/gb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gfx/gb.c b/src/gfx/gb.c index 22ab2b2f..2391a656 100644 --- a/src/gfx/gb.c +++ b/src/gfx/gb.c @@ -224,7 +224,11 @@ void create_mapfiles(const struct Options *opts, struct GBImage *gb, if (!tile) err(1, "%s: Failed to allocate memory for tile", __func__); - for (i = 0; i < tile_size; i++) { + /* + * If the input image doesn't fill the last tile, + * `gb_i` will reach `gb_size`. + */ + for (i = 0; i < tile_size && gb_i < gb_size; i++) { tile[i] = gb->data[gb_i]; gb_i++; }