From b4a3eb240e1ff7f2924b9095b73a044a0ac5ae78 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 11 Feb 2022 16:52:51 +0100 Subject: [PATCH] pattern: Don't allow negative array sizes --- lib/libimhex/include/hex/pattern_language/ast_node.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/libimhex/include/hex/pattern_language/ast_node.hpp b/lib/libimhex/include/hex/pattern_language/ast_node.hpp index f1b2bf384..797c2fbbc 100644 --- a/lib/libimhex/include/hex/pattern_language/ast_node.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast_node.hpp @@ -969,7 +969,7 @@ namespace hex::pl { evaluator->dataOffset() = startOffset; - u128 entryCount = 0; + i128 entryCount = 0; if (this->m_size != nullptr) { auto sizeNode = this->m_size->evaluate(evaluator); @@ -988,6 +988,9 @@ namespace hex::pl { evaluator->handleAbort(); } } + + if (entryCount < 0) + LogConsole::abortEvaluation("array cannot have a negative size", this); } else { std::vector buffer(templatePattern->getSize()); while (true) {