http.postbuffer: allow full range of ssize_t values

Unfortunately, in order to push some large repos where a server does not support chunked encoding, the http postbuffer must sometimes exceed two gigabytes. On a 64-bit system, this is OK: we just malloc a larger buffer. This means that we need to use CURLOPT_POSTFIELDSIZE_LARGE to set the buffer size. Signed-off-by: David Turner <dturner@twosigma.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Turner committed Apr 11, 2017 at 14:13 UTC 37ee680d9b90fe4c4fc5be4e14f17baf49f6ce59
5 files changed +32 -6
cache.h
+1
@@ -1901,6 +1901,7 @@ extern int git_parse_maybe_bool(const char *);
1901 extern int git_config_int(const char *, const char *);
1902 extern int64_t git_config_int64(const char *, const char *);
1903 extern unsigned long git_config_ulong(const char *, const char *);
1904 +extern ssize_t git_config_ssize_t(const char *, const char *);
1905 extern int git_config_bool_or_int(const char *, const char *, int *);
1906 extern int git_config_bool(const char *, const char *);
1907 extern int git_config_maybe_bool(const char *, const char *);
config.c
+17
@@ -834,6 +834,15 @@ int git_parse_ulong(const char *value, unsigned long *ret)
834 return 1;
835 }
836
837 +static int git_parse_ssize_t(const char *value, ssize_t *ret)
838 +{
839 + intmax_t tmp;
840 + if (!git_parse_signed(value, &tmp, maximum_signed_value_of_type(ssize_t)))
841 + return 0;
842 + *ret = tmp;
843 + return 1;
844 +}
845 +
846 NORETURN
847 static void die_bad_number(const char *name, const char *value)
848 {
@@ -892,6 +901,14 @@ unsigned long git_config_ulong(const char *name, const char *value)
901 return ret;
902 }
903
904 +ssize_t git_config_ssize_t(const char *name, const char *value)
905 +{
906 + ssize_t ret;
907 + if (!git_parse_ssize_t(value, &ret))
908 + die_bad_number(name, value);
909 + return ret;
910 +}
911 +
912 int git_parse_maybe_bool(const char *value)
913 {
914 if (!value)
http.c
+4 -2
@@ -19,7 +19,7 @@ long int git_curl_ipresolve;
19 #endif
20 int active_requests;
21 int http_is_verbose;
22 -size_t http_post_buffer = 16 * LARGE_PACKET_MAX;
22 +ssize_t http_post_buffer = 16 * LARGE_PACKET_MAX;
23
24 #if LIBCURL_VERSION_NUM >= 0x070a06
25 #define LIBCURL_CAN_HANDLE_AUTH_ANY
@@ -331,7 +331,9 @@ static int http_options(const char *var, const char *value, void *cb)
331 }
332
333 if (!strcmp("http.postbuffer", var)) {
334 - http_post_buffer = git_config_int(var, value);
334 + http_post_buffer = git_config_ssize_t(var, value);
335 + if (http_post_buffer < 0)
336 + warning(_("negative value for http.postbuffer; defaulting to %d"), LARGE_PACKET_MAX);
337 if (http_post_buffer < LARGE_PACKET_MAX)
338 http_post_buffer = LARGE_PACKET_MAX;
339 return 0;
http.h
+1 -1
@@ -111,7 +111,7 @@ extern struct curl_slist *http_copy_default_headers(void);
111 extern long int git_curl_ipresolve;
112 extern int active_requests;
113 extern int http_is_verbose;
114 -extern size_t http_post_buffer;
114 +extern ssize_t http_post_buffer;
115 extern struct credential http_auth;
116
117 extern char curl_errorstr[CURL_ERROR_SIZE];
remote-curl.c
+9 -3
@@ -531,6 +531,12 @@ static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
531 return err;
532 }
533
534 +static curl_off_t xcurl_off_t(ssize_t len) {
535 + if (len > maximum_signed_value_of_type(curl_off_t))
536 + die("cannot handle pushes this big");
537 + return (curl_off_t) len;
538 +}
539 +
540 static int post_rpc(struct rpc_state *rpc)
541 {
542 struct active_request_slot *slot;
@@ -614,7 +620,7 @@ retry:
620 * and we just need to send it.
621 */
622 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
617 - curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
623 + curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, xcurl_off_t(gzip_size));
624
625 } else if (use_gzip && 1024 < rpc->len) {
626 /* The client backend isn't giving us compressed data so
@@ -645,7 +651,7 @@ retry:
651
652 headers = curl_slist_append(headers, "Content-Encoding: gzip");
653 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
648 - curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
654 + curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, xcurl_off_t(gzip_size));
655
656 if (options.verbosity > 1) {
657 fprintf(stderr, "POST %s (gzip %lu to %lu bytes)\n",
@@ -658,7 +664,7 @@ retry:
664 * more normal Content-Length approach.
665 */
666 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, rpc->buf);
661 - curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, rpc->len);
667 + curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, xcurl_off_t(rpc->len));
668 if (options.verbosity > 1) {
669 fprintf(stderr, "POST %s (%lu bytes)\n",
670 rpc->service_name, (unsigned long)rpc->len);