diff --git a/docs/changelog.txt b/docs/changelog.txt index abd1b845fc0..fd4ebe33224 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::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`. diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 7e5707fccbf..5d0ca3766de 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -363,7 +363,20 @@ df::map_block *Maps::getTileBlock (int32_t x, int32_t y, int32_t z) { if (!isValidTilePos(x,y,z)) return NULL; - return world->map.block_index[x >> 4][y >> 4][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 || + block_index[bx][by][z] == NULL) { + return NULL; + } + + return world->map.block_index[bx][by][z]; } df::map_block *Maps::ensureTileBlock (int32_t x, int32_t y, int32_t z)