Bound what one stream read inflates when there is no payload limit

With a zero payload limit, StreamHandle::read_with_decompression() held
everything a compressed read inflated to in memory with no bound, and
SSEClient always reads its stream with a zero limit. Keep a single read
within the default payload limit, while the stream as a whole stays
unbounded.
This commit is contained in:
yhirose committed 2026-12-05 11:28:46 -06:00
1 parent 5fd66e46df
commit d81a932f2a
2 files changed
+46 -4

No files matched your search

+9 -4
View File
@@ -17463,6 +17463,14 @@ inline ssize_t ClientImpl::StreamHandle::read_with_decompression(char *buf,
constexpr size_t kDecompressionBufferSize = 8192;
char compressed_buf[kDecompressionBufferSize];
auto limit = body_reader_.payload_max_length;
auto counted = decompressed_bytes_read_;
if (limit == 0) {
// The stream is unbounded, but one read holds all it inflates at once
limit = CPPHTTPLIB_PAYLOAD_MAX_LENGTH;
counted = 0;
}
while (true) {
auto n = detail::read_body_content(stream_, body_reader_, compressed_buf,
sizeof(compressed_buf));
@@ -17474,10 +17482,7 @@ inline ssize_t ClientImpl::StreamHandle::read_with_decompression(char *buf,
compressed_buf, static_cast<size_t>(n),
[&](const char *data, size_t data_len) {
decompress_buffer_.append(data, data_len);
auto limit = body_reader_.payload_max_length;
exceeded =
limit > 0 &&
decompressed_bytes_read_ + decompress_buffer_.size() > limit;
exceeded = limit > 0 && counted + decompress_buffer_.size() > limit;
return !exceeded;
});