Improve imported object handling (#8372)

Reject and report invalid objects rather than triggering assert.
This commit is contained in:
Michał Janiszewski 2018-12-05 23:12:22 +01:00 committed by GitHub
parent f5f3bfe087
commit cec86469f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -221,8 +221,9 @@ namespace ObjectFactory
result->SetSourceGames({ object_entry_get_source_game_legacy(&entry) });
}
}
catch (const std::exception&)
catch (const std::exception& e)
{
log_error("Error: %s when processing object %s", e.what(), path);
delete result;
result = nullptr;
}

View File

@ -23,9 +23,10 @@
constexpr size_t MAX_UNCOMPRESSED_CHUNK_SIZE = 16 * 1024 * 1024;
constexpr const char* EXCEPTION_MSG_CORRUPT_CHUNK_SIZE = "Corrupt chunk size.";
constexpr const char* EXCEPTION_MSG_CORRUPT_RLE = "Corrupt RLE compression data.";
constexpr const char* EXCEPTION_MSG_DESTINATION_TOO_SMALL = "Chunk data larger than allocated destination capacity.";
constexpr const char* EXCEPTION_MSG_INVALID_CHUNK_ENCODING = "Invalid chunk encoding.";
constexpr const char* EXCEPTION_MSG_CORRUPT_RLE = "Corrupt RLE compression data.";
constexpr const char* EXCEPTION_MSG_ZERO_SIZED_CHUNK = "Encountered zero-sized chunk.";
class SawyerChunkException : public IOException
{
@ -82,7 +83,10 @@ std::shared_ptr<SawyerChunk> SawyerChunkReader::ReadChunk()
auto buffer = (uint8_t*)AllocateLargeTempBuffer();
size_t uncompressedLength = DecodeChunk(buffer, MAX_UNCOMPRESSED_CHUNK_SIZE, compressedData.get(), header);
Guard::Assert(uncompressedLength != 0, "Encountered zero-sized chunk!");
if (uncompressedLength == 0)
{
throw SawyerChunkException(EXCEPTION_MSG_ZERO_SIZED_CHUNK);
}
buffer = (uint8_t*)FinaliseLargeTempBuffer(buffer, uncompressedLength);
return std::make_shared<SawyerChunk>((SAWYER_ENCODING)header.encoding, buffer, uncompressedLength);
}