Skip to content

Commit 4fe24b3

Browse files
committed
[MP/SP] Increase MAX_ANIM_FILES from 16 to 64, add MAX_ANIM_EVENT_FILES
Fixes #817 - spawning more than 16 different NPC types causes a crash due to out-of-bounds array access in bgAllEvents[]. Split limits into MAX_ANIM_FILES (64) for animation skeletons and MAX_ANIM_EVENT_FILES (128) for event files, since multiple models can share a skeleton while having unique animevents.cfg files. Add bounds checking in BG_ParseAnimationEvtFile and BG_AnimsetAlloc to prevent out-of-bounds access if limits are exceeded.
1 parent e76263d commit 4fe24b3

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

code/game/bg_public.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ class animation_t
486486
}
487487
}; // animation_t
488488

489-
#define MAX_ANIM_FILES 16
489+
#define MAX_ANIM_FILES 64
490490
#define MAX_ANIM_EVENTS 300
491491

492492
//size of Anim eventData array...

codemp/game/bg_panimate.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,11 @@ void BG_ClearAnimsets(void)
17101710
animation_t *BG_AnimsetAlloc(void)
17111711
{
17121712
assert (bgNumAllAnims < MAX_ANIM_FILES);
1713+
if (bgNumAllAnims >= MAX_ANIM_FILES)
1714+
{
1715+
Com_Printf(S_COLOR_YELLOW "BG_AnimsetAlloc: MAX_ANIM_FILES reached (%d)\n", MAX_ANIM_FILES);
1716+
return NULL;
1717+
}
17131718
bgAllAnims[bgNumAllAnims].anims = (animation_t *) BG_Alloc(sizeof(animation_t)*MAX_TOTALANIMATIONS);
17141719

17151720
return bgAllAnims[bgNumAllAnims].anims;
@@ -2129,7 +2134,7 @@ This file's presence is not required
21292134
21302135
======================
21312136
*/
2132-
bgLoadedEvents_t bgAllEvents[MAX_ANIM_FILES];
2137+
bgLoadedEvents_t bgAllEvents[MAX_ANIM_EVENT_FILES];
21332138
int bgNumAnimEvents = 1;
21342139
static int bg_animParseIncluding = 0;
21352140
int BG_ParseAnimationEvtFile( const char *as_filename, int animFileIndex, int eventFileIndex )
@@ -2148,7 +2153,7 @@ int BG_ParseAnimationEvtFile( const char *as_filename, int animFileIndex, int ev
21482153
int forcedIndex;
21492154

21502155
assert(animFileIndex < MAX_ANIM_FILES);
2151-
assert(eventFileIndex < MAX_ANIM_FILES);
2156+
assert(eventFileIndex < MAX_ANIM_EVENT_FILES);
21522157

21532158
if (eventFileIndex == -1)
21542159
{
@@ -2159,6 +2164,12 @@ int BG_ParseAnimationEvtFile( const char *as_filename, int animFileIndex, int ev
21592164
forcedIndex = eventFileIndex;
21602165
}
21612166

2167+
if (forcedIndex >= MAX_ANIM_EVENT_FILES)
2168+
{
2169+
Com_Printf(S_COLOR_YELLOW "BG_ParseAnimationEvtFile: MAX_ANIM_EVENT_FILES reached (%d), using index 0 for %s\n", MAX_ANIM_EVENT_FILES, as_filename);
2170+
return 0;
2171+
}
2172+
21622173
if (bg_animParseIncluding <= 0)
21632174
{ //if we should be parsing an included file, skip this part
21642175
if ( bgAllEvents[forcedIndex].eventsParsed )

codemp/game/bg_public.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ typedef struct animation_s {
321321
extern qboolean BGPAFtextLoaded;
322322
extern animation_t bgHumanoidAnimations[MAX_TOTALANIMATIONS];
323323

324-
#define MAX_ANIM_FILES 16
324+
#define MAX_ANIM_FILES 64
325+
#define MAX_ANIM_EVENT_FILES 128
325326
#define MAX_ANIM_EVENTS 300
326327

327328
typedef enum
@@ -417,7 +418,7 @@ extern bgLoadedAnim_t bgAllAnims[MAX_ANIM_FILES];
417418
//On the bright side this also means we're cutting a rather large size out of
418419
//required game-side memory.
419420
#ifndef _GAME
420-
extern bgLoadedEvents_t bgAllEvents[MAX_ANIM_FILES];
421+
extern bgLoadedEvents_t bgAllEvents[MAX_ANIM_EVENT_FILES];
421422
extern int bgNumAnimEvents;
422423
#endif
423424

0 commit comments

Comments
 (0)