From 83e8729256070a43fe43c2a20904d2ea3af473cd Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Thu, 20 Jun 2024 20:19:19 +0200 Subject: [PATCH] Check the result of loading from bytecode --- components/lua/luastate.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/lua/luastate.cpp b/components/lua/luastate.cpp index 3cf6378f2f..26b832bdf9 100644 --- a/components/lua/luastate.cpp +++ b/components/lua/luastate.cpp @@ -386,7 +386,14 @@ namespace LuaUtil { auto iter = mCompiledScripts.find(path); if (iter != mCompiledScripts.end()) - return mSol.load(iter->second.as_string_view(), path, sol::load_mode::binary); + { + sol::load_result res = mSol.load(iter->second.as_string_view(), path, sol::load_mode::binary); + // Unless we have memory corruption issues, the bytecode is valid at this point, but loading might still + // fail because we've hit our Lua memory cap + if (!res.valid()) + throw std::runtime_error("Lua error: " + res.get()); + return res; + } sol::function res = loadFromVFS(path); mCompiledScripts[path] = res.dump(); return res;