Index: util/net/http_body.cc |
diff --git a/util/net/http_body.cc b/util/net/http_body.cc |
index cd31ab4fa568f45dc6e1c41db087393367ebd3d5..0e5daa34259a57816c91e5d60b9a4eeb4b7d3d9f 100644 |
--- a/util/net/http_body.cc |
+++ b/util/net/http_body.cc |
@@ -97,20 +97,25 @@ CompositeHTTPBodyStream::~CompositeHTTPBodyStream() { |
} |
ssize_t CompositeHTTPBodyStream::GetBytesBuffer(uint8_t* buffer, |
- size_t max_len) { |
- if (current_part_ == parts_.end()) |
- return 0; |
- |
- ssize_t rv = (*current_part_)->GetBytesBuffer(buffer, max_len); |
- |
- if (rv == 0) { |
- // If the current part has returned 0 indicating EOF, advance the current |
- // part and call recursively to try again. |
- ++current_part_; |
- return GetBytesBuffer(buffer, max_len); |
+ size_t buffer_len) { |
+ ssize_t max_len = std::min( |
+ buffer_len, implicit_cast<size_t>(std::numeric_limits<ssize_t>::max())); |
+ ssize_t bytes_copied = 0; |
+ while (bytes_copied < max_len && current_part_ != parts_.end()) { |
+ ssize_t this_read = (*current_part_)->GetBytesBuffer( |
+ buffer + bytes_copied, max_len - bytes_copied); |
+ |
+ if (this_read == 0) { |
+ // If the current part has returned 0 indicating EOF, advance the current |
+ // part and try again. |
+ ++current_part_; |
+ } else if (this_read < 0) { |
+ return this_read; |
+ } |
+ bytes_copied += this_read; |
} |
- return rv; |
+ return bytes_copied; |
} |
} // namespace crashpad |