diff --git a/src/Common.cpp b/src/Common.cpp index 52aea27..ada2dd6 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -390,6 +390,9 @@ void SplitString(const std::string& str, const char delim, std::vector DeComp(std::span input) { beammp_debugf("got {} bytes of input data", input.size()); + // start with a decompression buffer of 5x the input size, clamped to a maximum of 15 MB. + // this buffer can and will grow, but we don't want to start it too large. A 5x compression ratio + // is pretty optimistic. std::vector output_buffer(std::min(input.size() * 5, 15 * 1024 * 1024)); uLongf output_size = output_buffer.size(); @@ -401,6 +404,9 @@ std::vector DeComp(std::span input) { reinterpret_cast(input.data()), static_cast(input.size())); if (res == Z_BUF_ERROR) { + // We assume that a reasonable maximum size for decompressed packets is 30 MB. + // If this were to be an issue, this could be made configurable, however clients have a similar + // limit. For that reason, we just reject packets which decompress into too much data. if (output_buffer.size() > 30 * 1024 * 1024) { throw std::runtime_error("decompressed packet size of 30 MB exceeded"); }