From ce425f730fba40d83737223cc1bc26a1e030e099 Mon Sep 17 00:00:00 2001 From: Dan Van Twisk Date: Sun, 18 May 2025 00:51:48 -0400 Subject: [PATCH 1/6] Safe getTileBlock --- library/modules/Maps.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 7e5707fccb..42861810a0 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -363,6 +363,16 @@ df::map_block *Maps::getTileBlock (int32_t x, int32_t y, int32_t z) { if (!isValidTilePos(x,y,z)) return NULL; + + auto &block_index = world->map.block_index; + + if (block_index == NULL || + block_index[bx] == NULL || + block_index[bx][by] == NULL || + block_index[bx][by][z] == NULL) { + return NULL; + } + return world->map.block_index[x >> 4][y >> 4][z]; } From 678cc78eee1a48b6c3ce28ebb0c62716ead9f12a Mon Sep 17 00:00:00 2001 From: Dan Van Twisk Date: Sun, 18 May 2025 01:00:17 -0400 Subject: [PATCH 2/6] documentation for getTileBlock change --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index abd1b845fc..c2240c43dd 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -64,6 +64,7 @@ Template for new versions: - `preserve-rooms`: don't warn when a room is assigned to a non-existent unit. this is now common behavior for DF when it keeps a room for an unloaded unit - fixed an overly restrictive type constraint that resulted in some object types being glossed as a boolean when passed as an argument from C++ to Lua - `plants`: will no longer generate a traceback when a filter is used +- `Maps`: added a check in getTileBlock to ensure it does not access unallocated blocks. ## Misc Improvements - All places where units are listed in DFHack tools now show the translated English name in addition to the native name. In particular, this makes units searchable by English name in `gui/sitemap`. From 31d34f3b21237c58e63e69ae9f1aecc36f2cbd67 Mon Sep 17 00:00:00 2001 From: Dan Van Twisk Date: Sun, 18 May 2025 01:16:40 -0400 Subject: [PATCH 3/6] documentation for getTileBlock fix --- docs/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index c2240c43dd..fd4ebe3322 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -64,7 +64,7 @@ Template for new versions: - `preserve-rooms`: don't warn when a room is assigned to a non-existent unit. this is now common behavior for DF when it keeps a room for an unloaded unit - fixed an overly restrictive type constraint that resulted in some object types being glossed as a boolean when passed as an argument from C++ to Lua - `plants`: will no longer generate a traceback when a filter is used -- `Maps`: added a check in getTileBlock to ensure it does not access unallocated blocks. +- ``Maps::getTileBlock``: added a check in getTileBlock to ensure it does not access unallocated blocks. ## Misc Improvements - All places where units are listed in DFHack tools now show the translated English name in addition to the native name. In particular, this makes units searchable by English name in `gui/sitemap`. From 2474b13f3eb5434f984cfc6082e4e516a13684e4 Mon Sep 17 00:00:00 2001 From: Dan Van Twisk Date: Sun, 18 May 2025 01:26:19 -0400 Subject: [PATCH 4/6] Fix to getBlockTile change --- library/modules/Maps.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 42861810a0..5d0ca3766d 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -366,6 +366,9 @@ df::map_block *Maps::getTileBlock (int32_t x, int32_t y, int32_t z) auto &block_index = world->map.block_index; + int32_t bx = x >> 4; + int32_t by = y >> 4; + if (block_index == NULL || block_index[bx] == NULL || block_index[bx][by] == NULL || @@ -373,7 +376,7 @@ df::map_block *Maps::getTileBlock (int32_t x, int32_t y, int32_t z) return NULL; } - return world->map.block_index[x >> 4][y >> 4][z]; + return world->map.block_index[bx][by][z]; } df::map_block *Maps::ensureTileBlock (int32_t x, int32_t y, int32_t z) From 236352d26b35ac9c92cb09ad77f4f76850ebe25a Mon Sep 17 00:00:00 2001 From: Dan Van Twisk Date: Sun, 18 May 2025 18:59:05 -0400 Subject: [PATCH 5/6] Ci Bump --- library/modules/Maps.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 5d0ca3766d..7b8af1c73a 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -373,7 +373,7 @@ df::map_block *Maps::getTileBlock (int32_t x, int32_t y, int32_t z) block_index[bx] == NULL || block_index[bx][by] == NULL || block_index[bx][by][z] == NULL) { - return NULL; + return NULL; } return world->map.block_index[bx][by][z]; From f1cbaab97036876c7f1f8209d9f4b1b2a00a6b18 Mon Sep 17 00:00:00 2001 From: Dan Van Twisk Date: Sun, 18 May 2025 19:01:22 -0400 Subject: [PATCH 6/6] Remove trailing white-space --- library/modules/Maps.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 7b8af1c73a..5d0ca3766d 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -373,7 +373,7 @@ df::map_block *Maps::getTileBlock (int32_t x, int32_t y, int32_t z) block_index[bx] == NULL || block_index[bx][by] == NULL || block_index[bx][by][z] == NULL) { - return NULL; + return NULL; } return world->map.block_index[bx][by][z];