diff --git a/src/lib/file.cpp b/src/lib/file.cpp index 5406d28..b0da8ab 100644 --- a/src/lib/file.cpp +++ b/src/lib/file.cpp @@ -61,10 +61,12 @@ ErrorOr File::readByte(){ uint8_t* nextPointer = new uint8_t; uint8_t nextByte; bool failure = false; + if (!this->size.isError && this->cursorPosition >= this->size.value) { + return ErrorOr(true, ErrorCodes::OVERRUN); + } try { this->fileStream.seekg(this->cursorPosition); - //FIXME: check that a byte is available for read this->fileStream.read(reinterpret_cast(nextPointer), 1); nextByte = *nextPointer; @@ -81,6 +83,9 @@ ErrorOr> File::read(uint64_t bytes){ uint8_t* buffer = new uint8_t[bytes]; std::vector data; bool failure = false; + if (!this->size.isError && this->cursorPosition >= this->size.value+bytes) { + return ErrorOr>(true, ErrorCodes::OVERRUN); + } try { this->fileStream.seekg(this->cursorPosition);