diff options
| author | Dan Engelbrecht <[email protected]> | 2024-04-13 13:53:24 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-04-13 13:53:24 +0200 |
| commit | 06708ea1c044215eee37a2703b6764cf2e89d53b (patch) | |
| tree | dfd6fec18aa35bd97504a2c97698c9c657981da7 /src/zencore/include | |
| parent | typo fix in gc.lightweightintervalseconds (diff) | |
| download | zen-06708ea1c044215eee37a2703b6764cf2e89d53b.tar.xz zen-06708ea1c044215eee37a2703b6764cf2e89d53b.zip | |
Validate input buffer size when trying to parse package message (#47)
* add validation of input buffer size when trying to parse package message
* avoid doing memcopy when parsing package message
Diffstat (limited to 'src/zencore/include')
| -rw-r--r-- | src/zencore/include/zencore/stream.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/zencore/include/zencore/stream.h b/src/zencore/include/zencore/stream.h index a28290041..fae393666 100644 --- a/src/zencore/include/zencore/stream.h +++ b/src/zencore/include/zencore/stream.h @@ -70,14 +70,25 @@ public: inline void Read(void* DataPtr, size_t ByteCount) { + ZEN_ASSERT(m_Offset + ByteCount <= m_BufferSize); memcpy(DataPtr, m_BufferBase + m_Offset, ByteCount); m_Offset += ByteCount; } + inline MemoryView GetView(size_t ByteCount) const + { + ZEN_ASSERT(m_Offset + ByteCount <= m_BufferSize); + return MemoryView((const void*)(m_BufferBase + m_Offset), (const void*)(m_BufferBase + m_Offset + ByteCount)); + } inline uint64_t Size() const { return m_BufferSize; } inline uint64_t GetSize() const { return Size(); } inline uint64_t CurrentOffset() const { return m_Offset; } - inline void Skip(size_t ByteCount) { m_Offset += ByteCount; }; + inline uint64_t Remaining() const { return m_BufferSize - m_Offset; } + inline void Skip(size_t ByteCount) + { + ZEN_ASSERT(m_Offset + ByteCount <= m_BufferSize); + m_Offset += ByteCount; + }; protected: const uint8_t* m_BufferBase; |