Fix PSv parsing

I took extra care to not mess up signedness in readOPS in ab600780d0, but apparently didn't do the same in readPSv.

Also fix a bound check that was broken since aac6b7258c. It's a good thing this was broken, because this allowed negative type values from broken signedness readPSv to get past and cause a crash later on, rather than just cause particles to disappear or something.
This commit is contained in:
Tamás Bálint Misius 2022-12-11 08:51:58 +01:00
parent b57db7991a
commit 54cd259a18
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
2 changed files with 5 additions and 4 deletions

View File

@ -1317,8 +1317,8 @@ void GameSave::readPSv(const std::vector<char> &dataVec)
if (size > 209715200 || !size)
throw ParseException(ParseException::InvalidDimensions, "Save data too large");
std::vector<char> data;
switch (auto status = BZ2WDecompress(data, (char *)(saveData + 12), dataLength - 12, size))
std::vector<char> bsonData;
switch (auto status = BZ2WDecompress(bsonData, (char *)(saveData + 12), dataLength - 12, size))
{
case BZ2WDecompressOk: break;
case BZ2WDecompressNomem: throw ParseException(ParseException::Corrupt, "Cannot allocate memory");
@ -1326,7 +1326,8 @@ void GameSave::readPSv(const std::vector<char> &dataVec)
}
setSize(bw, bh);
dataLength = data.size();
const auto *data = reinterpret_cast<unsigned char *>(&bsonData[0]);
dataLength = bsonData.size();
#ifdef DEBUG
std::cout << "Parsing " << dataLength << " bytes of data, version " << ver << std::endl;

View File

@ -105,7 +105,7 @@ int Simulation::Load(const GameSave * originalSave, bool includePressure, int fu
}
int type = tempPart->type;
if (type < 0 && type >= PT_NUM)
if (type < 0 || type >= PT_NUM)
{
tempPart->type = 0;
continue;