{"thread":{"id":"2091","subject":"[PATCH] git-http-fetch: Remove size limit for objects/info/{packs,alternates}","startedAt":"2005-10-13T16:01:48Z","lastAt":"2005-10-13T16:01:48Z","messageCount":1,"participants":["Sergey Vlasov"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"10072","messageId":"20051013160148.GB12092@master.mivlgu.local","threadId":"2091","inReplyTo":null,"subject":"[PATCH] git-http-fetch: Remove size limit for objects/info/{packs,alternates}","fromName":"Sergey Vlasov","fromEmail":"vsu@altlinux.ru","sentAt":"2005-10-13T16:01:48Z","receivedAt":"2005-10-13T16:01:48Z","isPatch":true,"sender":{"key":"vsu@altlinux.ru","avatar":"https://avatars.githubusercontent.com/u/616082?v=4"},"body":"git-http-fetch received objects/info/packs into a fixed-size buffer\nand started to fail when this file became larger than the buffer.\nChange it to grow the buffer dynamically, and do the same thing for\nobjects/info/alternates.  Also add missing free() calls for these\nbuffers.\n\nSigned-off-by: Sergey Vlasov <vsu@altlinux.ru>\n\n\n---\n\n The problem currently happens with the linux-2.4 repository:\n\n http://www.kernel.org/pub/scm/linux/kernel/git/marcelo/linux-2.4.git/\n\n For some reason, objects/info/packs in that repository has grown to 662K.\n\n\n http-fetch.c |   43 ++++++++++++++++++++++++++++++++++++-------\n 1 files changed, 36 insertions(+), 7 deletions(-)\n\napplies-to: 1970e5869a42fd4095917d861654dc84d60f02b7\n341e03b5a2f197b1e60c3d38c0803d552dc6cd4d\ndiff --git a/http-fetch.c b/http-fetch.c\nindex 0aba891..c6daf6a 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -110,6 +110,22 @@ static size_t fwrite_buffer(void *ptr, s\n         return size;\n }\n \n+static size_t fwrite_buffer_dynamic(const void *ptr, size_t eltsize,\n+\t\t\t\t    size_t nmemb, struct buffer *buffer)\n+{\n+\tsize_t size = eltsize * nmemb;\n+\tif (size > buffer->size - buffer->posn) {\n+\t\tbuffer->size = buffer->size * 3 / 2;\n+\t\tif (buffer->size < buffer->posn + size)\n+\t\t\tbuffer->size = buffer->posn + size;\n+\t\tbuffer->buffer = xrealloc(buffer->buffer, buffer->size);\n+\t}\n+\tmemcpy(buffer->buffer + buffer->posn, ptr, size);\n+\tbuffer->posn += size;\n+\tdata_received++;\n+\treturn size;\n+}\n+\n static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,\n \t\t\t       void *data)\n {\n@@ -618,11 +634,12 @@ static int fetch_alternates(char *base)\n \tint i = 0;\n \tint http_specific = 1;\n \tstruct alt_base *tail = alt;\n+\tstatic const char null_byte = '\\0';\n \n \tstruct active_request_slot *slot;\n \n \tdata = xmalloc(4096);\n-\tbuffer.size = 4095;\n+\tbuffer.size = 4096;\n \tbuffer.posn = 0;\n \tbuffer.buffer = data;\n \n@@ -634,7 +651,8 @@ static int fetch_alternates(char *base)\n \n \tslot = get_active_slot();\n \tcurl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION,\n+\t\t\t fwrite_buffer_dynamic);\n \tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n@@ -646,20 +664,24 @@ static int fetch_alternates(char *base)\n \t\t\tslot = get_active_slot();\n \t\t\tcurl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);\n \t\t\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION,\n-\t\t\t\t\t fwrite_buffer);\n+\t\t\t\t\t fwrite_buffer_dynamic);\n \t\t\tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n \t\t\tif (start_active_slot(slot)) {\n \t\t\t\trun_active_slot(slot);\n \t\t\t\tif (slot->curl_result != CURLE_OK) {\n+\t\t\t\t\tfree(buffer.buffer);\n \t\t\t\t\treturn 0;\n \t\t\t\t}\n \t\t\t}\n \t\t}\n \t} else {\n+\t\tfree(buffer.buffer);\n \t\treturn 0;\n \t}\n \n-\tdata[buffer.posn] = '\\0';\n+\tfwrite_buffer_dynamic(&null_byte, 1, 1, &buffer);\n+\tbuffer.posn--;\n+\tdata = buffer.buffer;\n \n \twhile (i < buffer.posn) {\n \t\tint posn = i;\n@@ -718,7 +740,8 @@ static int fetch_alternates(char *base)\n \t\t}\n \t\ti = posn + 1;\n \t}\n-\t\n+\n+\tfree(buffer.buffer);\n \treturn ret;\n }\n \n@@ -748,17 +771,22 @@ static int fetch_indices(struct alt_base\n \n \tslot = get_active_slot();\n \tcurl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION,\n+\t\t\t fwrite_buffer_dynamic);\n \tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n \tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n-\t\tif (slot->curl_result != CURLE_OK)\n+\t\tif (slot->curl_result != CURLE_OK) {\n+\t\t\tfree(buffer.buffer);\n \t\t\treturn error(\"%s\", curl_errorstr);\n+\t\t}\n \t} else {\n+\t\tfree(buffer.buffer);\n \t\treturn error(\"Unable to start request\");\n \t}\n \n+\tdata = buffer.buffer;\n \twhile (i < buffer.posn) {\n \t\tswitch (data[i]) {\n \t\tcase 'P':\n@@ -778,6 +806,7 @@ static int fetch_indices(struct alt_base\n \t\ti++;\n \t}\n \n+\tfree(buffer.buffer);\n \trepo->got_indices = 1;\n \treturn 0;\n }\n---\n0.99.8.GIT\n"}]}