Skip to content

Commit

Permalink
Revert "Properly abort reading from a bitstream in CLuaArgument::Read…
Browse files Browse the repository at this point in the history
…FromBitStream"

This reverts commit 7fabb15.
  • Loading branch information
fcs49 committed Sep 21, 2018
1 parent 9393d58 commit bd13c5c
Showing 1 changed file with 112 additions and 119 deletions.
231 changes: 112 additions & 119 deletions Server/mods/deathmatch/logic/lua/CLuaArgument.cpp
Expand Up @@ -14,7 +14,7 @@
extern CGame* g_pGame;

#ifndef VERIFY_ELEMENT
#define VERIFY_ELEMENT(element) (g_pGame->GetMapManager()->GetRootElement()->IsMyChild(element, true) && !element->IsBeingDeleted())
#define VERIFY_ELEMENT(element) (g_pGame->GetMapManager()->GetRootElement ()->IsMyChild(element,true)&&!element->IsBeingDeleted())
#endif

using namespace std;
Expand Down Expand Up @@ -458,158 +458,151 @@ bool CLuaArgument::ReadFromBitStream(NetBitStreamInterface& bitStream, std::vect
SLuaTypeSync type;

// Read out the type
if (!bitStream.Read(&type))
return false;

// Depending on what type...
switch (type.data.ucType)
if (bitStream.Read(&type))
{
// Nil type
case LUA_TNIL:
{
m_iType = LUA_TNIL;
return true;
;
}

// Boolean type
case LUA_TBOOLEAN:
// Depending on what type...
switch (type.data.ucType)
{
bool bValue;
if (!bitStream.ReadBit(bValue))
return false;
// Nil type
case LUA_TNIL:
{
m_iType = LUA_TNIL;
break;
}

ReadBool(bValue);
return true;
}
// Boolean type
case LUA_TBOOLEAN:
{
bool bValue;
if (bitStream.ReadBit(bValue))
ReadBool(bValue);
break;
}

// Number type
case LUA_TNUMBER:
{
if (bitStream.ReadBit())
// Number type
case LUA_TNUMBER:
{
if (bitStream.ReadBit())
{
double dNum;
if (bitStream.Read(dNum))
ReadNumber(dNum);
if (bitStream.ReadBit())
{
double dNum;
if (bitStream.Read(dNum))
ReadNumber(dNum);
}
else
return false;
{
float fNum;
if (bitStream.Read(fNum))
ReadNumber(RoundFromFloatSource(fNum));
}
}
else
{
float fNum;
if (bitStream.Read(fNum))
ReadNumber(RoundFromFloatSource(fNum));
else
return false;
int iNum;
if (bitStream.ReadCompressed(iNum))
ReadNumber(iNum);
}
break;
}

int iNum;
if (bitStream.ReadCompressed(iNum))
ReadNumber(iNum);
else
return false;
}

// Table type
case LUA_TTABLE:
{
m_pTableData = new CLuaArguments();
if (!m_pTableData->ReadFromBitStream(bitStream, pKnownTables))
return false;
m_bWeakTableRef = false;
m_iType = LUA_TTABLE;
m_pTableData->ValidateTableKeys();
return true;
}

// Table reference
case LUA_TTABLEREF:
{
unsigned long ulTableRef;
if (!bitStream.ReadCompressed(ulTableRef))
return false;

if (pKnownTables && ulTableRef < pKnownTables->size())
// Table type
case LUA_TTABLE:
{
m_pTableData = pKnownTables->at(ulTableRef);
m_bWeakTableRef = true;
m_pTableData = new CLuaArguments();
if(!m_pTableData->ReadFromBitStream(bitStream, pKnownTables))
return false;
m_bWeakTableRef = false;
m_iType = LUA_TTABLE;
return true;
}
else
{
return false;
m_pTableData->ValidateTableKeys();
break;
}
}

// String type
case LUA_TSTRING:
{
// Read out the string length
unsigned short usLength;
if (bitStream.ReadCompressed(usLength) && usLength > 0)
// Table reference
case LUA_TTABLEREF:
{
if (!bitStream.CanReadNumberOfBytes(usLength))
return false;
// Allocate a buffer and read the string into it
std::string strValue(usLength, '\0');
if (bitStream.Read(&strValue[0], usLength))
unsigned long ulTableRef;
if (bitStream.ReadCompressed(ulTableRef))
{
// Put it into us
ReadString(strValue);
return true;
if (pKnownTables && ulTableRef < pKnownTables->size())
{
m_pTableData = pKnownTables->at(ulTableRef);
m_bWeakTableRef = true;
m_iType = LUA_TTABLE;
}
}
return false;
break;
}

return true;
}

// Long string type
case LUA_TSTRING_LONG:
{
// Read out the string length
uint uiLength;
if (bitStream.ReadCompressed(uiLength) && uiLength > 0)
// String type
case LUA_TSTRING:
{
if (!bitStream.CanReadNumberOfBytes(uiLength))
return false;

bitStream.AlignReadToByteBoundary();
// Allocate a buffer and read the string into it
std::string strValue(uiLength, '\0');
if (bitStream.Read(&strValue[0], uiLength))
// Read out the string length
unsigned short usLength;
if (bitStream.ReadCompressed(usLength) && usLength > 0)
{
// Put it into us
ReadString(strValue);
return true;
if (!bitStream.CanReadNumberOfBytes(usLength))
return false;
// Allocate a buffer and read the string into it
char* szValue = new char[usLength + 1];
if (bitStream.Read(szValue, usLength))
{
// Put it into us
ReadString(std::string(szValue, usLength));
}

// Delete the buffer
delete[] szValue;
}
return false;
}
else
ReadString("");

return true;
}
break;
}

// Element type?
case LUA_TLIGHTUSERDATA:
case LUA_TUSERDATA:
{
ElementID ElementID;
if (bitStream.Read(ElementID))
// Long string type
case LUA_TSTRING_LONG:
{
ReadElementID(ElementID);
return true;
// Read out the string length
uint uiLength;
if (bitStream.ReadCompressed(uiLength) && uiLength > 0)
{
if(!bitStream.CanReadNumberOfBytes(uiLength))
return false;

bitStream.AlignReadToByteBoundary();

// Allocate a buffer and read the string into it
char* szValue = new char[uiLength + 1];
assert(szValue);
if (bitStream.Read(szValue, uiLength))
{
// Put it into us
ReadString(std::string(szValue, uiLength));
}

// Delete the buffer
delete[] szValue;
}
else
ReadString("");

break;
}
else

// Element type?
case LUA_TLIGHTUSERDATA:
case LUA_TUSERDATA:
{
return false;
ElementID ElementID;
if (bitStream.Read(ElementID))
{
ReadElementID(ElementID);
}
break;
}
}
}

return true;
}

Expand Down

0 comments on commit bd13c5c

Please sign in to comment.