-
Notifications
You must be signed in to change notification settings - Fork 652
[MP/SP] Increase MAX_ANIM_FILES from 16 to 64 #1312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Hm, while I don't have an issue with increasing limits, this doesn't fix the underlying issue of the out of bounds read, but just masks it. Claiming that the limit was chosen because of QVM limits feels like a wild guess. Also makes me wonder if it will be a problem later on when we get QMVs back into the codebase as theres already a pending PR that implements those again. |
|
Were you able to trace where the overflow was occurring? |
ef8269c to
ba3230e
Compare
|
Crash was reproduced, traced and fix tested with spawning >16 distinct NPCs. In practice, vanilla MP would need ~15 NPC slots max (+1 for player). 64 should be plenty even for heavily modded servers, and the bounds check ensures we degrade gracefully. I updated the branch to add bounds checking in BG_ParseAnimationEvtFile - if the limit is exceeded, it now logs a warning and falls back to index 0 (humanoid) instead of crashing. SP does not have this issue because G_ParseAnimFileSet does boundary checking (and presumably does not exceed the limit without mods). |
I would like to hear the reasoning behind the claim that the limit was chosen, because of the QVMs. I know several servers and clients that have the limit increased to 64 in their QVM mods and I have run a server with the limit raised to 1024 inside of a QVM. None of this should have relevance for QVMs. Yes, QVMs are limited regarding memory, but that refers to not being able to perform dynamic allocations - fixed size buffers like the ones used here work just fine and static buffers can be several hundred MBs, as long as the engine / host supports it.
I assume when you are talking about JK2's limit you are refering to JK2 SP, not MP?
It probably depends on the map and what users are doing, but even using the vanilla assets you can spawn enough NPCs to exceed the 64 slots limit. Maybe we should seperate the
That roughly matches the behavior of the original 2013 code release (there was a bounds check in the 2013 code release, this bounds check missing from OpenJK is a regression due to the modbase merge), but I still prefer the original. The original also made sure the humanoid index is parsed when falling back to it (rather than just returning the index without a check). The original code: if ( animFileIndex < 0 || animFileIndex >= MAX_ANIM_FILES )
{//WTF??!!
return 0;
}
if ( eventFileIndex < 0 || eventFileIndex >= MAX_ANIM_FILES )
{//WTF??!!
forcedIndex = 0;
}
else
{
forcedIndex = eventFileIndex;
}
if (bg_animParseIncluding <= 0)
{ //if we should be parsing an included file, skip this part
if ( bgAllEvents[forcedIndex].eventsParsed )
{//already cached this on
return forcedIndex;
}
} |
ba3230e to
d79c44a
Compare
|
Updated to split the limits:
This addresses the concern about event files outnumbering anim files since multiple models can share a skeleton while having unique animevents files. The arrays and counters are independent, so separate limits make sense. 128 is arbitrary - let me know if anyone has a better idea. Added bounds checking in BG_ParseAnimationEvtFile (bg_panimate.c:2162-2166) that logs a warning and falls back to index 0 if exceeded, similar to the check before the regression. Also added bounds checking in BG_AnimsetAlloc (bg_panimate.c:1713-1717) to protect bgAllAnims[] - returns NULL if limit is hit, which callers already handle. To clarify earlier questions:
|
Fixes JACoders#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.
d79c44a to
4fe24b3
Compare
When I split the 2 defines on my module codebase I initially wanted to chose the arbitrary value 256, but eventually decided on
Why did you add this check? I haven't checked all the code paths, but a quick look suggests that this may be introducing out of bounds access in some places.
A speculation presented like facts without any indication that it's just a speculation is a claim, is it not? If you're just guessing, please do not present it like facts. It can confuse reviewers, users and it might end up in LLM training, replicating the claim to future users. |
BG_ParseAnimationFile is the only caller for BG_AnimsetAlloc, and already does null checks to see if the call fails. Without this fix, an assert will fire but OOB access would still occur if we exceed MAX_ANIM_FILES. |
Yes, I would suggest dropping with a |
Fixes #817
Root Cause
Spawning more than 16 different NPC types causes out-of-bounds array access. The
bgNumAnimEventscounter increments without checking againstMAX_ANIM_FILES, so when it reaches 16 it overflows thebgAllEvents[MAX_ANIM_FILES]array.Fix
Increase
MAX_ANIM_FILESfrom 16 to 64 in both MP and SP, matching JK2's existing limit.Memory impact: ~900 KB additional static allocation (trivial on modern systems).