From 1e511acf37e3993236685866012d8f3ad3c2ac7a Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 14 Jun 2022 10:17:50 +0200 Subject: [PATCH] fix: More vector out of bounds accesses --- .../source/content/views/view_hex_editor.cpp | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 9b0997127..501dca091 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -754,21 +754,21 @@ namespace hex::plugin::builtin { const bool cellHovered = ImGui::IsMouseHoveringRect(cellStartPos, cellStartPos + cellSize, true); - this->handleSelection(byteAddress, bytesPerCell, &bytes[x], cellHovered); - - auto [foregroundColor, backgroundColor] = cellColors[x / bytesPerCell]; - - // Draw highlights and selection - if (backgroundColor.has_value()) { - auto drawList = ImGui::GetWindowDrawList(); - - // Draw background color - drawList->AddRectFilled(cellStartPos, cellStartPos + cellSize, backgroundColor.value()); - - this->drawSelectionFrame(x, y, byteAddress, 1, cellStartPos, cellSize); - } - if (x < validBytes) { + this->handleSelection(byteAddress, bytesPerCell, &bytes[x], cellHovered); + + auto [foregroundColor, backgroundColor] = cellColors[x / bytesPerCell]; + + // Draw highlights and selection + if (backgroundColor.has_value()) { + auto drawList = ImGui::GetWindowDrawList(); + + // Draw background color + drawList->AddRectFilled(cellStartPos, cellStartPos + cellSize, backgroundColor.value()); + + this->drawSelectionFrame(x, y, byteAddress, 1, cellStartPos, cellSize); + } + if (std::isprint(bytes[x])) ImGui::TextFormatted("{:c}", bytes[x]); else @@ -808,21 +808,24 @@ namespace hex::plugin::builtin { const auto cellSize = CharacterSize * data.advance; const bool cellHovered = ImGui::IsMouseHoveringRect(cellStartPos, cellStartPos + cellSize, true); - auto [foregroundColor, backgroundColor] = cellColors[address % this->m_bytesPerRow]; + const auto x = address % this->m_bytesPerRow; + if (x < validBytes) { + auto [foregroundColor, backgroundColor] = cellColors[x]; - // Draw highlights and selection - if (backgroundColor.has_value()) { - auto drawList = ImGui::GetWindowDrawList(); + // Draw highlights and selection + if (backgroundColor.has_value()) { + auto drawList = ImGui::GetWindowDrawList(); - // Draw background color - drawList->AddRectFilled(cellStartPos, cellStartPos + cellSize, backgroundColor.value()); + // Draw background color + drawList->AddRectFilled(cellStartPos, cellStartPos + cellSize, backgroundColor.value()); - this->drawSelectionFrame(address % this->m_bytesPerRow, y, address, 1, cellStartPos, cellSize); + this->drawSelectionFrame(x, y, address, 1, cellStartPos, cellSize); + } + + ImGui::TextFormattedColored(data.color, "{}", data.displayValue); + + this->handleSelection(address, data.advance, &bytes[address % this->m_bytesPerRow], cellHovered); } - - ImGui::TextFormattedColored(data.color, "{}", data.displayValue); - - this->handleSelection(address, data.advance, &bytes[address % this->m_bytesPerRow], cellHovered); } ImGui::EndTable();