From 6faeadaceb5e70c0891caf94b68573c559eebc75 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 3 Dec 2018 18:10:36 +0100 Subject: [PATCH] - hardened the seg integrity checks against extremely broken mods. Temple of the Lizardmen 3 has segs lumps in every level that seem to use a different data format and are completely unusable, up to triggering undefined behavior. --- src/p_setup.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index e7079fe50..b7489bf92 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -1176,12 +1176,12 @@ template void P_LoadSegs (MapData * map) { uint8_t *data; - int numvertexes = level.vertexes.Size(); + uint32_t numvertexes = level.vertexes.Size(); uint8_t *vertchanged = new uint8_t[numvertexes]; // phares 10/4/98 uint32_t segangle; //int ptp_angle; // phares 10/4/98 //int delta_angle; // phares 10/4/98 - int vnum1,vnum2; // phares 10/4/98 + uint32_t vnum1,vnum2; // phares 10/4/98 int lumplen = map->Size(ML_SEGS); memset (vertchanged,0,numvertexes); // phares 10/4/98 @@ -1300,6 +1300,10 @@ void P_LoadSegs (MapData * map) ldef = &level.lines[linedef]; li->linedef = ldef; side = LittleShort(ml->side); + if (side != 0 && side != 1) + { + throw badseg(3, i, side); + } if ((unsigned)(ldef->sidedef[side]->Index()) >= level.sides.Size()) { throw badseg(2, i, ldef->sidedef[side]->Index()); @@ -1334,6 +1338,10 @@ void P_LoadSegs (MapData * map) case 2: Printf ("The linedef for seg %d references a nonexistant sidedef %d (max %d).\n", bad.badsegnum, bad.baddata, level.sides.Size()); break; + + case 3: + Printf("Sidedef reference in seg %d is %d (must be 0 or 1).\n", bad.badsegnum, bad.baddata); + break; } Printf ("The BSP will be rebuilt.\n"); level.segs.Clear();