Added a check to prevent buffer sync buffer overflow, and expand buff… (#937)

* Added a check to prevent buffer sync buffer overflow, and expand buffer size if needed.

* Removed unnecessary asserts and added sync buffer overflow check to encode template
This commit is contained in:
Gene Payne
2019-08-12 13:25:56 -06:00
committed by GitHub
parent 798ba573cf
commit dc45be045b
2 changed files with 11 additions and 3 deletions

View File

@@ -35,9 +35,13 @@ SyncBuffer::SyncBuffer(size_t n)
SyncBuffer::~SyncBuffer() {} // NOLINT
void SyncBuffer::encode(const std::string& s) {
ghoul_assert(_encodeOffset + sizeof(char) * s.size() + sizeof(int32_t) < _n, "");
int32_t anticpatedBufferSize = _encodeOffset + (sizeof(char) * s.size())
+ sizeof(int32_t);
if (anticpatedBufferSize >= _n) {
_dataStream.resize(anticpatedBufferSize);
}
int32_t length = static_cast<int32_t>(s.length());
int32_t length = static_cast<int32_t>(s.size() * sizeof(char));
memcpy(
_dataStream.data() + _encodeOffset,
reinterpret_cast<const char*>(&length),