From d050973fa47750b9cdc45398d26c940f36bfecbc Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 12 May 2010 10:17:08 +0000 Subject: [PATCH] - added blockmap verification code. SVN r2320 (trunk) --- src/p_setup.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 45f50c64e..8c3f774d7 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -2721,6 +2721,79 @@ static void P_CreateBlockMap () } } + + +// +// P_VerifyBlockMap +// +// haleyjd 03/04/10: do verification on validity of blockmap. +// +static bool P_VerifyBlockMap(int count) +{ + int x, y; + int *maxoffs = blockmaplump + count; + + int bmapwidth = blockmaplump[2]; + int bmapheight = blockmaplump[3]; + + for(y = 0; y < bmapheight; y++) + { + for(x = 0; x < bmapwidth; x++) + { + int offset; + int *list, *tmplist; + int *blockoffset; + + offset = y * bmapwidth + x; + blockoffset = blockmaplump + offset + 4; + + + // check that block offset is in bounds + if(blockoffset >= maxoffs) + { + Printf(PRINT_HIGH, "P_VerifyBlockMap: block offset overflow\n"); + return false; + } + + offset = *blockoffset; + + // check that list offset is in bounds + if(offset < 4 || offset >= count) + { + Printf(PRINT_HIGH, "P_VerifyBlockMap: list offset overflow\n"); + return false; + } + + list = blockmaplump + offset; + + // scan forward for a -1 terminator before maxoffs + for(tmplist = list; ; tmplist++) + { + // we have overflowed the lump? + if(tmplist >= maxoffs) + { + Printf(PRINT_HIGH, "P_VerifyBlockMap: open blocklist\n"); + return false; + } + if(*tmplist == -1) // found -1 + break; + } + + // scan the list for out-of-range linedef indicies in list + for(tmplist = list; *tmplist != -1; tmplist++) + { + if(*tmplist < 0 || *tmplist >= numlines) + { + Printf(PRINT_HIGH, "P_VerifyBlockMap: index >= numlines\n"); + return false; + } + } + } + } + + return true; +} + // // P_LoadBlockMap // @@ -2768,6 +2841,13 @@ void P_LoadBlockMap (MapData * map) blockmaplump[i] = t == -1 ? (DWORD)0xffffffff : (DWORD) t & 0xffff; } delete[] data; + + if (!P_VerifyBlockMap(count)) + { + DPrintf ("Generating BLOCKMAP\n"); + P_CreateBlockMap(); + } + } bmaporgx = blockmaplump[0]<