From 4e01518ce2bf63f51579caa6ccc533e58722c7ea Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 6 Feb 2020 17:37:34 +1100 Subject: [PATCH] Don't terminate the game if the server sends a bogus map whosevolume != dimensions --- src/Protocol.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Protocol.c b/src/Protocol.c index c0e60b9f5..822596e26 100644 --- a/src/Protocol.c +++ b/src/Protocol.c @@ -396,6 +396,15 @@ static void MapState_Init(struct MapState* m) { m->allocFailed = false; } +static void FreeMapStates(void) { + Mem_Free(map.blocks); + map.blocks = NULL; +#ifdef EXTENDED_BLOCKS + Mem_Free(map2.blocks); + map2.blocks = NULL; +#endif +} + static void MapState_Read(struct MapState* m) { cc_uint32 left, read; if (m->allocFailed) return; @@ -510,15 +519,18 @@ static void Classic_LevelFinalise(cc_uint8* data) { if (map.allocFailed) return; #ifdef EXTENDED_BLOCKS - if (map2.allocFailed) { Mem_Free(map.blocks); map.blocks = NULL; return; } + if (map2.allocFailed) { FreeMapStates(); return; } #endif - width = Stream_GetU16_BE(&data[0]); - height = Stream_GetU16_BE(&data[2]); - length = Stream_GetU16_BE(&data[4]); + width = Stream_GetU16_BE(data + 0); + height = Stream_GetU16_BE(data + 2); + length = Stream_GetU16_BE(data + 4); if (map_volume != (width * height * length)) { - Logger_Abort("Blocks array size does not match volume of map"); + Chat_AddRaw("&cFailed to load map, try joining a different map"); + Chat_AddRaw(" &cBlocks array size does not match volume of map"); + FreeMapStates(); + return; } World_SetNewMap(map.blocks, width, height, length);