Add checks to AssetBuffers before they are used (#820)

* add checks to buffers before they are used
to avoid crashing

* address feedback
This commit is contained in:
Aaron Kimbrell 2022-11-10 12:59:31 -06:00 committed by GitHub
parent 7c2437173b
commit 1eff3ae454
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 1 deletions

View File

@ -344,6 +344,11 @@ void Item::DisassembleModel() {
std::string lxfmlPath = "BrickModels/" + GeneralUtils::SplitString(renderAssetSplit.back(), '.').at(0) + ".lxfml";
auto buffer = Game::assetManager->GetFileAsBuffer(lxfmlPath.c_str());
if (!buffer.m_Success) {
Game::logger->Log("Item", "Failed to load %s to disassemble model into bricks, check that this file exists", lxfmlPath.c_str());
return;
}
std::istream file(&buffer);
result.finalize();

View File

@ -19,6 +19,11 @@ std::vector<Brick>& BrickDatabase::GetBricks(const std::string& lxfmlPath) {
}
AssetMemoryBuffer buffer = Game::assetManager->GetFileAsBuffer((lxfmlPath).c_str());
if (!buffer.m_Success) {
return emptyCache;
}
std::istream file(&buffer);
if (!file.good()) {
return emptyCache;

View File

@ -584,6 +584,12 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
if (args[0].find("\\") != std::string::npos) return;
auto buf = Game::assetManager->GetFileAsBuffer(("macros/" + args[0] + ".scm").c_str());
if (!buf.m_Success){
ChatPackets::SendSystemMessage(sysAddr, u"Unknown macro! Is the filename right?");
return;
}
std::istream infile(&buf);
if (infile.good()) {

View File

@ -42,6 +42,12 @@ void Zone::LoadZoneIntoMemory() {
if (m_ZoneFilePath == "ERR") return;
AssetMemoryBuffer buffer = Game::assetManager->GetFileAsBuffer(m_ZoneFilePath.c_str());
if (!buffer.m_Success) {
Game::logger->Log("Zone", "Failed to load %s", m_ZoneFilePath.c_str());
throw std::runtime_error("Aborting Zone loading due to no Zone File.");
}
std::istream file(&buffer);
if (file) {
BinaryIO::BinaryRead(file, m_ZoneFileFormatVersion);
@ -265,7 +271,10 @@ std::vector<LUTriggers::Trigger*> Zone::LoadLUTriggers(std::string triggerFile,
auto buffer = Game::assetManager->GetFileAsBuffer((m_ZonePath + triggerFile).c_str());
if (!buffer.m_Success) return lvlTriggers;
if (!buffer.m_Success) {
Game::logger->Log("Zone", "Failed to load %s from disk. Skipping loading triggers", (m_ZonePath + triggerFile).c_str());
return lvlTriggers;
}
std::istream file(&buffer);
std::stringstream data;