Skip to content

Commit

Permalink
Fix #1993
Browse files Browse the repository at this point in the history
  • Loading branch information
yhirose committed Nov 30, 2024
1 parent 4f5b003 commit 457fc43
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -7983,9 +7983,7 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
: static_cast<ContentReceiverWithProgress>(
[&](const char *buf, size_t n, uint64_t /*off*/,
uint64_t /*len*/) {
if (res.body.size() + n > res.body.max_size()) {
return false;
}
assert(res.body.size() + n <= res.body.max_size());
res.body.append(buf, n);
return true;
});
Expand All @@ -7999,9 +7997,12 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,

if (res.has_header("Content-Length")) {
if (!req.content_receiver) {
auto len = std::min<size_t>(res.get_header_value_u64("Content-Length"),
res.body.max_size());
if (len > 0) { res.body.reserve(len); }
auto len = res.get_header_value_u64("Content-Length");
if (len > res.body.max_size()) {
error = Error::Read;
return false;
}
res.body.reserve(len);
}
}

Expand Down

0 comments on commit 457fc43

Please sign in to comment.