check for missized rejectmatrix´s on load, pad them if needed

this is what dsda-doom/prboom does
ensures we wont crash from oob reads and makes us print a warning
This commit is contained in:
alufolie91 committed 2026-06-13 13:00:00 +02:00
1 parent b24f6683b7
commit cc6437285f
4 files changed
+22 -24

No files matched your search

+1 -7
View File
@@ -414,13 +414,7 @@ boolean P_DoSpring(mobj_t *spring, mobj_t *object);
//
// P_SETUP
//
typedef struct
{
UINT8* data;
size_t size;
} reject_t;
extern reject_t rejectmatrix; // for fast sight rejection
extern UINT8 *rejectmatrix; // for fast sight rejection
extern INT32 *blockmaplump; // offsets in blockmap are from here
extern INT32 *blockmap; // Big blockmap
extern INT32 bmapwidth;
+18 -11
View File
@@ -145,7 +145,7 @@ precipmobj_t **precipblocklinks = NULL;
// Speeds up enemy AI by skipping detailed LineOf Sight calculation.
// Without special effect, this could be used as a PVS lookup as well.
//
reject_t rejectmatrix = {};
UINT8 *rejectmatrix = NULL;
// Maintain single and multi player starting spots.
INT32 numdmstarts = 0, numcoopstarts = 0, numredctfstarts = 0, numbluectfstarts = 0;
@@ -1780,23 +1780,29 @@ static void P_GroupLines(void)
}
}
// PK3 version
// -- Monster Iestyn 09/01/18
static void P_LoadReject(UINT8 *data, size_t count)
static void P_LoadReject(UINT8 *data, size_t rejectsize)
{
if (!count) // zero length, someone probably used ZDBSP
const size_t neededsize = (numsectors * numsectors + 7) >> 3;
size_t allocsize = rejectsize;
if (!rejectsize) // zero length, someone probably used ZDBSP
{
rejectmatrix.data = NULL;
rejectmatrix = NULL;
CONS_Debug(DBG_SETUP, "P_LoadReject: REJECT lump has size 0, will not be loaded\n");
}
else
{
rejectmatrix.data = Z_Malloc(count, PU_LEVEL, NULL); // allocate memory for the reject matrix
memcpy(rejectmatrix.data, data, count); // copy the data into it
}
if (rejectsize < neededsize)
{
CONS_Alert(CONS_WARNING, "REJECT is %lu byte%s too small. REJECT might be invalid and might crash vanilla clients!\n", (neededsize - rejectsize), (neededsize - rejectsize) == 1 ? "" : "s");
allocsize = neededsize;
}
rejectmatrix.size = count;
rejectmatrix = Z_Calloc(allocsize, PU_LEVEL, NULL); // allocate memory for the reject matrix
memcpy(rejectmatrix, data, rejectsize); // copy the data into it
}
}
static void P_LoadMapBSP(const virtres_t* virt)
@@ -1833,11 +1839,12 @@ static void P_LoadMapLUT(const virtres_t* virt)
// Lookup tables
if (virtreject)
{
P_LoadReject(virtreject->data, virtreject->size);
}
else
{
rejectmatrix.data = NULL;
rejectmatrix.size = 0;
rejectmatrix = NULL;
}
if (!(virtblockmap && P_LoadRawBlockMap(virtblockmap->data, virtblockmap->size)))
+2 -5
View File
@@ -373,13 +373,10 @@ boolean P_CheckSight2(mobj_t *t1, mobj_t *t2, boolean fast)
s2 = t2->subsector->sector;
pnum = (s1-sectors)*numsectors + (s2-sectors);
if (rejectmatrix.data != NULL)
if (rejectmatrix != NULL)
{
const size_t shiftnum = pnum>>3;
// Check in REJECT table.
if (shiftnum < rejectmatrix.size && // check for overflow
(rejectmatrix.data[shiftnum] & (1 << (pnum&7)))) // can't possibly be connected
if (rejectmatrix[pnum>>3] & (1 << (pnum&7))) // can't possibly be connected
{
return false;
}
+1 -1
View File
@@ -586,7 +586,7 @@ void Y_Ticker(void)
if (data.rankingsmode && intertic > sorttic+16+(2*TICRATE))
{
INT32 q=0,r=0;
INT32 q = 0, r = 0;
boolean kaching = true;
for (q = 0; q < data.numplayers; q++)