Skip to content

Commit

Permalink
catch potential ParseExceptions when loading saves, use bson error ha…
Browse files Browse the repository at this point in the history
…ndler to prevent exit(-5)
  • Loading branch information
jacob1 committed Aug 14, 2016
1 parent 97a9f41 commit 6dc1c22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/client/GameSave.cpp
Expand Up @@ -439,6 +439,11 @@ void GameSave::Transform(matrix2d transform, vector2d translate)
fanVelYPtr = (float*)fanVelYPtrNew;
}

void bson_error_handler(const char *err)
{
throw ParseException(ParseException::Corrupt, "BSON error when parsing save");
}

void GameSave::readOPS(char * data, int dataLength)
{
unsigned char * inputData = (unsigned char*)data, *bsonData = NULL, *partsData = NULL, *partsPosData = NULL, *fanData = NULL, *wallData = NULL, *soapLinkData = NULL;
Expand Down Expand Up @@ -500,6 +505,7 @@ void GameSave::readOPS(char * data, int dataLength)
if (BZ2_bzBuffToBuffDecompress((char*)bsonData, &bsonDataLen, (char*)(inputData+12), inputDataLen-12, 0, 0))
throw ParseException(ParseException::Corrupt, "Unable to decompress");

set_bson_err_handler(bson_error_handler);
bson_init_data(&b, (char*)bsonData);
bson_iterator_init(&iter, &b);

Expand Down
12 changes: 10 additions & 2 deletions src/simulation/Simulation.cpp
Expand Up @@ -33,8 +33,16 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
{
int blockX, blockY, x, y, r;

if(!save) return 1;
save->Expand();
if (!save)
return 1;
try
{
save->Expand();
}
catch (ParseException)
{
return 1;
}

//Align to blockMap
blockX = (fullX + CELL/2)/CELL;
Expand Down

0 comments on commit 6dc1c22

Please sign in to comment.