Skip to content

Commit aa8b2c0

Browse files
committed
httpclient: don't read more than the client wants
When `git_http_client_read_body` is invoked, it provides the size of the buffer that can be read into. This will be set as the parser context's `output_size` member. Use this as an upper limit on our reads, and ensure that we do not read more than the client requests.
1 parent 570f034 commit aa8b2c0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/transports/httpclient.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,7 @@ static int http_client_connect(
10381038

10391039
GIT_INLINE(int) client_read(git_http_client *client)
10401040
{
1041+
http_parser_context *parser_context = client->parser.data;
10411042
git_stream *stream;
10421043
char *buf = client->read_buf.ptr + client->read_buf.size;
10431044
size_t max_len;
@@ -1054,6 +1055,9 @@ GIT_INLINE(int) client_read(git_http_client *client)
10541055
max_len = client->read_buf.asize - client->read_buf.size;
10551056
max_len = min(max_len, INT_MAX);
10561057

1058+
if (parser_context->output_size)
1059+
max_len = min(max_len, parser_context->output_size);
1060+
10571061
if (max_len == 0) {
10581062
git_error_set(GIT_ERROR_HTTP, "no room in output buffer");
10591063
return -1;

0 commit comments

Comments
 (0)