aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/include
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-04-13 13:53:24 +0200
committerGitHub Enterprise <[email protected]>2024-04-13 13:53:24 +0200
commit06708ea1c044215eee37a2703b6764cf2e89d53b (patch)
treedfd6fec18aa35bd97504a2c97698c9c657981da7 /src/zencore/include
parenttypo fix in gc.lightweightintervalseconds (diff)
downloadzen-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.h13
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;