From b8c7a29b8409f1f95abbbb23371ed31a41d2dea1 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 2 Feb 2022 07:50:25 -0500 Subject: [PATCH] OOB protection in GetLineCharAtIdx --- IDEHelper/Compiler/BfParser.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/IDEHelper/Compiler/BfParser.cpp b/IDEHelper/Compiler/BfParser.cpp index d72553da..d721244a 100644 --- a/IDEHelper/Compiler/BfParser.cpp +++ b/IDEHelper/Compiler/BfParser.cpp @@ -239,7 +239,16 @@ int BfParserData::GetCharIdAtIndex(int findIndex) } void BfParserData::GetLineCharAtIdx(int idx, int& line, int& lineChar) -{ +{ + if (mJumpTableSize <= 0) + { + line = 0; + lineChar = 0; + return; + } + + if (idx >= mSrcLength) + idx = mSrcLength - 1; auto* jumpEntry = mJumpTable + (idx / PARSER_JUMPTABLE_DIVIDE); if (jumpEntry->mCharIdx > idx) jumpEntry--;