From 6c8d844ec535d8e4db0c6aabfae3317aa8aa3926 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Tue, 7 Apr 2020 16:26:22 +0300 Subject: [PATCH] PPU LLVM: fix crash on damaged cache files --- Utilities/JIT.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Utilities/JIT.cpp b/Utilities/JIT.cpp index 056f32c981..a53dd7a942 100644 --- a/Utilities/JIT.cpp +++ b/Utilities/JIT.cpp @@ -965,6 +965,11 @@ public: std::vector gz = cached.to_vector(); std::vector out; z_stream zs{}; + + if (gz.empty()) [[unlikely]] + { + return nullptr; + } #ifndef _MSC_VER #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wold-style-cast" @@ -1015,6 +1020,11 @@ public: if (fs::file cached{path, fs::read}) { + if (cached.size() == 0) [[unlikely]] + { + return nullptr; + } + auto buf = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(cached.size()); cached.read(buf->getBufferStart(), buf->getBufferSize()); return buf; @@ -1208,6 +1218,11 @@ bool jit_compiler::check(const std::string& path) { return true; } + + if (fs::remove_file(path)) + { + jit_log.error("ObjectCache: Removed damaged file: %s", path); + } } return false;