From 9d5a56a40b6f25548ebc364c590ab891c9bbe8ba Mon Sep 17 00:00:00 2001 From: Chloe Marcec Date: Sun, 7 Feb 2021 23:52:56 +1100 Subject: lm: Fix ReadLeb128 Fixes assertion on Bloodstained Ritual of the Night. We would over read sometimes, this is fixed by checking if the top bit is set in the first iteration. We also lock the loop off to be only the max size of the type we can fit. Finally we changed an incorrect print of "DEBUG" to "TRACE" to reflect the proper log severity --- src/core/hle/service/lm/lm.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp index 2a6d43d2a..7d7542fc2 100644 --- a/src/core/hle/service/lm/lm.cpp +++ b/src/core/hle/service/lm/lm.cpp @@ -143,17 +143,19 @@ private: rb.Push(RESULT_SUCCESS); } - u32 ReadLeb128(const std::vector& data, std::size_t& offset) { - u32 result{}; + u64 ReadLeb128(const std::vector& data, std::size_t& offset) { + u64 result{}; u32 shift{}; - do { - result |= (data[offset] & 0x7f) << shift; + + for (std::size_t i = 0; i < sizeof(u64); i++) { + const auto v = data[offset]; + result |= (static_cast(v & 0x7f) << shift); shift += 7; offset++; - if (offset >= data.size()) { + if (offset >= data.size() || ((v & 0x80) == 0)) { break; } - } while ((data[offset] & 0x80) != 0); + } return result; } @@ -262,7 +264,7 @@ private: switch (entry.severity) { case LogSeverity::Trace: - LOG_DEBUG(Service_LM, "LogManager DEBUG ({}):\n{}", DestinationToString(destination), + LOG_DEBUG(Service_LM, "LogManager TRACE ({}):\n{}", DestinationToString(destination), output_log); break; case LogSeverity::Info: -- cgit v1.2.3