Skip to content
Permalink
Browse files

SaveState: Fail load on decompression error.

Simply checking the size isn't enough, because it doesn't write the
decompressed size in the case of invalid data.

May help the crash in #11890.
  • Loading branch information...
unknownbrackets committed Jun 23, 2019
1 parent 8c282db commit eaba867f28752e55ad2d1b2b29f456f7a9dc39fb
Showing with 10 additions and 2 deletions.
  1. +10 −2 Common/ChunkFile.cpp
@@ -249,19 +249,27 @@ CChunkFileReader::Error CChunkFileReader::LoadFile(const std::string &filename,
return ERROR_BAD_FILE;
}

_buffer = buffer;
if (header.Compress) {
u8 *uncomp_buffer = new u8[header.UncompressedSize];
size_t uncomp_size = header.UncompressedSize;
snappy_uncompress((const char *)buffer, sz, (char *)uncomp_buffer, &uncomp_size);
auto status = snappy_uncompress((const char *)buffer, sz, (char *)uncomp_buffer, &uncomp_size);
if (status != SNAPPY_OK) {
ERROR_LOG(SAVESTATE, "ChunkReader: Failed to decompress file");
delete [] uncomp_buffer;
delete [] buffer;
return ERROR_BAD_FILE;
}
if ((u32)uncomp_size != header.UncompressedSize) {
ERROR_LOG(SAVESTATE, "Size mismatch: file: %u calc: %u", header.UncompressedSize, (u32)uncomp_size);
delete [] uncomp_buffer;
delete [] buffer;
return ERROR_BAD_FILE;
}
_buffer = uncomp_buffer;
sz = uncomp_size;
delete [] buffer;
} else {
_buffer = buffer;
}

if (header.GitVersion[31]) {

0 comments on commit eaba867

Please sign in to comment.
You can’t perform that action at this time.