From 42b7e40f9deb5a7de240c74426429fc2f6e5cedc Mon Sep 17 00:00:00 2001 From: Shwoomple <> Date: Sat, 12 Nov 2022 10:58:27 +0530 Subject: [PATCH] lib/file:Fix issue #71 (Out of Bounds access) --- src/lib/file.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib/file.cpp b/src/lib/file.cpp index acb8e38..b5ca0c5 100644 --- a/src/lib/file.cpp +++ b/src/lib/file.cpp @@ -187,7 +187,7 @@ ErrorOrVoid File::insertByte(uint8_t byte){ this->fileStream.seekg(0); this->write(readData); this->cursorPosition++; - delete buffer; + delete[] buffer; }catch(std::exception& e){ failure = true; } @@ -209,7 +209,7 @@ ErrorOrVoid File::insert(std::vector data){ this->fileStream.seekg(0); this->write(readData); this->cursorPosition += data.size(); - delete buffer; + delete[] buffer; }catch(std::exception& e){ failure = true; } @@ -230,10 +230,9 @@ ErrorOrVoid File::insertString(tiny_utf8::string string){ this->fileStream.seekg(0); - //TODO: fix hack. tinyutf8 appends "_utf-8" when readData is assigned: tiny_utf8::string((char *) buffer); - this->writeString(readData.substr(0, readData.find("_utf-8"))); + this->writeString(readData); this->cursorPosition += string.size(); - delete buffer; + delete[] buffer; }catch(std::exception& e){ failure = true; } @@ -257,7 +256,7 @@ ErrorOr File::cutByte(){ this->fileStream.seekg(0); this->write(readData); this->cursorPosition++; - delete buffer; + delete[] buffer; }catch(std::exception& e){ failure = true; }