Skip to content

Commit

Permalink
Fixed jHexen: Added some basic checking for malformed ACS bytecode in…
Browse files Browse the repository at this point in the history
… P_LoadACScripts. Zero-length "dummy" BEHAVIOR lumps no longer cause a fatal error during map load. No point in doing anything more elaborate at this stage; the ACS-bytecode-to-Doomsday-Script interpreter is nearly completed and is already a lot more robust.
  • Loading branch information
danij-deng committed Jan 7, 2011
1 parent f1786b5 commit de7257c
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions doomsday/plugins/jhexen/src/p_acs.c
Expand Up @@ -61,11 +61,13 @@

// TYPES -------------------------------------------------------------------

#pragma pack(1)
typedef struct acsheader_s {
int marker;
int infoOffset;
int code;
int32_t marker;
int32_t infoOffset;
int32_t code;
} acsheader_t;
#pragma pack()

// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------

Expand Down Expand Up @@ -252,18 +254,29 @@ const char* GetACString(int id)

void P_LoadACScripts(int lump)
{
int i;
const int* buffer;
const acsheader_t* header;
acsinfo_t* info;

header = W_CacheLumpNum(lump, PU_MAP);
ActionCodeBase = (const byte*) header;
buffer = (int*) ((const byte*) header + LONG(header->infoOffset));
ACScriptCount = LONG(*buffer++);
size_t lumpLength = (lump >= 0? W_LumpLength(lump) : 0);
const acsheader_t* header;
const int* buffer;
acsinfo_t* info;
int i;

ACScriptCount = 0;

if(lumpLength >= sizeof(acsheader_t))
{
header = W_CacheLumpNum(lump, PU_MAP);
ActionCodeBase = (const byte*) header;

if(LONG(header->infoOffset) < (int)lumpLength)
{
buffer = (int*) ((const byte*) header + LONG(header->infoOffset));
ACScriptCount = LONG(*buffer++);
}
}

if(ACScriptCount == 0 || IS_CLIENT)
{ // Empty behavior lump
ACScriptCount = 0;
{ // Empty/Invalid lump.
Con_Message("Warning:P_LoadACSScripts: lumpnum %i does not appear to be valid ACS bytecode, ignoring.\n", lump);
return;
}

Expand Down

0 comments on commit de7257c

Please sign in to comment.