diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 5175efe5b..6bc6a5fee 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -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; @@ -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); diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 09c63333f..5fe3a571a 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -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;