From af59b9d2ca60e62b2367d9ab0a91cb0e1511caa3 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 7 Jun 2024 21:00:55 +0200 Subject: [PATCH] fix: Infinite loop when doing forwards/backwards searches in some cases Fixes #1734 --- lib/external/libwolv | 2 +- .../popups/hex_editor/popup_hex_editor_find.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/external/libwolv b/lib/external/libwolv index 101da1689211a..a34c241303d84 160000 --- a/lib/external/libwolv +++ b/lib/external/libwolv @@ -1 +1 @@ -Subproject commit 101da1689211a40c576b9d39d5cd38fa4c3d8c52 +Subproject commit a34c241303d846b3a080920d7c6b1579522c163d diff --git a/plugins/builtin/source/content/popups/hex_editor/popup_hex_editor_find.cpp b/plugins/builtin/source/content/popups/hex_editor/popup_hex_editor_find.cpp index 302de59f15c5b..d1ec7273089b7 100644 --- a/plugins/builtin/source/content/popups/hex_editor/popup_hex_editor_find.cpp +++ b/plugins/builtin/source/content/popups/hex_editor/popup_hex_editor_find.cpp @@ -211,11 +211,21 @@ namespace hex::plugin::builtin { } std::optional PopupFind::findByteSequence(const std::vector &sequence) const { + if (sequence.empty()) + return std::nullopt; + auto provider = ImHexApi::Provider::get(); + if (provider == nullptr) + return std::nullopt; + + const auto providerSize = provider->getActualSize(); + if (providerSize == 0x00) + return std::nullopt; + prv::ProviderReader reader(provider); auto startAbsolutePosition = provider->getBaseAddress(); - auto endAbsolutePosition = provider->getBaseAddress() + provider->getActualSize() - 1; + auto endAbsolutePosition = provider->getBaseAddress() + providerSize - 1; constexpr static auto searchFunction = [](const auto &haystackBegin, const auto &haystackEnd, const auto &needleBegin, const auto &needleEnd) {