mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-06-08 07:44:23 +00:00
add buffer size checking
This commit is contained in:
@@ -45,6 +45,12 @@ Sd0::Sd0(std::istream& buffer) {
|
|||||||
uint32_t bufferSize = buffer.tellg();
|
uint32_t bufferSize = buffer.tellg();
|
||||||
buffer.seekg(0, std::ios::beg);
|
buffer.seekg(0, std::ios::beg);
|
||||||
WriteSize(firstChunk, bufferSize);
|
WriteSize(firstChunk, bufferSize);
|
||||||
|
// its expected that if we got here, we got an old sd0 buffer where we ignored the sd0 part
|
||||||
|
// that means this can be at most the compressed chunk limit.
|
||||||
|
if (bufferSize > MAX_UNCOMPRESSED_CHUNK_SIZE) {
|
||||||
|
LOG("Possible bad chunk size of %i specified, rejecting.", bufferSize);
|
||||||
|
return;
|
||||||
|
}
|
||||||
firstChunk.resize(firstChunk.size() + bufferSize);
|
firstChunk.resize(firstChunk.size() + bufferSize);
|
||||||
auto* dataStart = reinterpret_cast<char*>(firstChunk.data() + GetDataOffset(true));
|
auto* dataStart = reinterpret_cast<char*>(firstChunk.data() + GetDataOffset(true));
|
||||||
if (!buffer.read(dataStart, bufferSize)) {
|
if (!buffer.read(dataStart, bufferSize)) {
|
||||||
@@ -71,7 +77,12 @@ Sd0::Sd0(std::istream& buffer) {
|
|||||||
|
|
||||||
WriteSize(chunk, chunkSize);
|
WriteSize(chunk, chunkSize);
|
||||||
|
|
||||||
// Possible overflow from a massive chunk or allocation of a massive chunk. TODO: fix this
|
// Assuming a good buffer that is large enough to take up 2 zlib buffers
|
||||||
|
// any buffer should be compressed enough to take up less size than its uncompressed counterpart
|
||||||
|
if (chunkSize > MAX_UNCOMPRESSED_CHUNK_SIZE) {
|
||||||
|
LOG("Possible bad chunk size of %i specified, rejecting.", chunkSize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
chunk.resize(chunkSize + dataOffset);
|
chunk.resize(chunkSize + dataOffset);
|
||||||
auto* dataStart = reinterpret_cast<char*>(chunk.data() + dataOffset);
|
auto* dataStart = reinterpret_cast<char*>(chunk.data() + dataOffset);
|
||||||
if (!buffer.read(dataStart, chunkSize)) {
|
if (!buffer.read(dataStart, chunkSize)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user