mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-14 10:29:35 +00:00
Treat a payload max length of 0 as unlimited on every read path
set_payload_max_length(0) is documented to disable the limit, but the readers for a chunked body and for a body delimited by the connection closing compared the size against the limit without checking for 0. A server configured that way answered a chunked request with 413, and a client failed to read a chunked or unframed response. A body with Content-Length was already unlimited. Give both readers the same `payload_max_length > 0` guard the other payload checks use.
This commit is contained in:
1 parent
8f094fe292
commit
84ff13ec47
2 files changed
+55
-4
No files matched your search
@@ -8412,8 +8412,9 @@ read_content_without_length(Stream &strm, size_t payload_max_length,
|
||||
if (n < 0) { return ReadContentResult::Error; }
|
||||
|
||||
// Check if adding this data would exceed the payload limit
|
||||
if (r > payload_max_length ||
|
||||
payload_max_length - r < static_cast<size_t>(n)) {
|
||||
if (payload_max_length > 0 &&
|
||||
(r > payload_max_length ||
|
||||
payload_max_length - r < static_cast<size_t>(n))) {
|
||||
return ReadContentResult::PayloadTooLarge;
|
||||
}
|
||||
|
||||
@@ -8448,8 +8449,9 @@ inline ReadContentResult read_content_chunked(Stream &strm, T &x,
|
||||
return ReadContentResult::Success;
|
||||
}
|
||||
|
||||
if (total_len > payload_max_length ||
|
||||
payload_max_length - total_len < static_cast<size_t>(n)) {
|
||||
if (payload_max_length > 0 &&
|
||||
(total_len > payload_max_length ||
|
||||
payload_max_length - total_len < static_cast<size_t>(n))) {
|
||||
return ReadContentResult::PayloadTooLarge;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user