From a5d202ffc8d4ef04ca823c3d74a666885695cfe1 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 13 Jun 2022 21:56:02 +0200 Subject: [PATCH] fix: Vector out of bounds access --- lib/external/pattern_language | 2 +- .../source/content/views/view_hex_editor.cpp | 32 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/external/pattern_language b/lib/external/pattern_language index 31ae5773b..55324f345 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit 31ae5773b099cb48cdd81bc8b6c01e6da94fe672 +Subproject commit 55324f345e955bdc8ba23b32feeae31acbbc3ffc diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index b701d063b..5053659b1 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -655,24 +655,26 @@ namespace hex::plugin::builtin { const auto cellBytes = std::min(validBytes, bytesPerCell); // Query cell colors - const auto foregroundColor = queryForegroundColor(byteAddress, &bytes[x], cellBytes); - const auto backgroundColor = [&]{ - auto color = queryBackgroundColor(byteAddress, &bytes[x], cellBytes); + if (x < validBytes) { + const auto foregroundColor = queryForegroundColor(byteAddress, &bytes[x], cellBytes); + const auto backgroundColor = [&]{ + auto color = queryBackgroundColor(byteAddress, &bytes[x], cellBytes); - if ((byteAddress >= selectionMin && byteAddress <= selectionMax)) { - if (color.has_value()) - color = ((ImAlphaBlendColors(color.value(), this->m_selectionColor)) & 0x00FFFFFF) | (this->m_selectionColor & 0xFF000000); - else - color = this->m_selectionColor; - } + if ((byteAddress >= selectionMin && byteAddress <= selectionMax)) { + if (color.has_value()) + color = ((ImAlphaBlendColors(color.value(), this->m_selectionColor)) & 0x00FFFFFF) | (this->m_selectionColor & 0xFF000000); + else + color = this->m_selectionColor; + } - return color; - }(); + return color; + }(); - cellColors.emplace_back( - foregroundColor, - backgroundColor - ); + cellColors.emplace_back( + foregroundColor, + backgroundColor + ); + } } }