Skip to contentSkip to conversation

http.postbuffer: allow full range of ssize_t values

PATCH Superseded David Turner 4 participants 4 messages Apr 3, 2017

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 http.postbuffer: allow full range of ssize_t values

Unfortunately, in order to push some large repos, 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.

---
 cache.h       |  1 +
 config.c      | 17 +++++++++++++++++
 http.c        |  4 ++--
 http.h        |  2 +-
 remote-curl.c |  6 +++---
 5 files changed, 24 insertions(+), 6 deletions(-)
cache.h +1 -0
index fbdf7a815a..5e6747dbb4 100644
@@ -1900,6 +1900,7 @@ extern int git_parse_maybe_bool(const char *);
 extern int git_config_int(const char *, const char *);
 extern int64_t git_config_int64(const char *, const char *);
 extern unsigned long git_config_ulong(const char *, const char *);
+extern ssize_t git_config_ssize_t(const char *, const char *);
 extern int git_config_bool_or_int(const char *, const char *, int *);
 extern int git_config_bool(const char *, const char *);
 extern int git_config_maybe_bool(const char *, const char *);
config.c +17 -0
index 1a4d85537b..de5b155a4e 100644
@@ -834,6 +834,15 @@ int git_parse_ulong(const char *value, unsigned long *ret)
 	return 1;
 }
 
+static int git_parse_ssize_t(const char *value, ssize_t *ret)
+{
+	ssize_t tmp;
+	if (!git_parse_signed(value, &tmp, maximum_signed_value_of_type(ssize_t)))
+		return 0;
+	*ret = tmp;
+	return 1;
+}
+
 NORETURN
 static void die_bad_number(const char *name, const char *value)
 {
@@ -892,6 +901,14 @@ unsigned long git_config_ulong(const char *name, const char *value)
 	return ret;
 }
 
+ssize_t git_config_ssize_t(const char *name, const char *value)
+{
+	ssize_t ret;
+	if (!git_parse_ssize_t(value, &ret))
+		die_bad_number(name, value);
+	return ret;
+}
+
 int git_parse_maybe_bool(const char *value)
 {
 	if (!value)
http.c +2 -2
index 96d84bbed3..22f8167ba2 100644
@@ -19,7 +19,7 @@ long int git_curl_ipresolve;
 #endif
 int active_requests;
 int http_is_verbose;
-size_t http_post_buffer = 16 * LARGE_PACKET_MAX;
+ssize_t http_post_buffer = 16 * LARGE_PACKET_MAX;
 
 #if LIBCURL_VERSION_NUM >= 0x070a06
 #define LIBCURL_CAN_HANDLE_AUTH_ANY
@@ -331,7 +331,7 @@ static int http_options(const char *var, const char *value, void *cb)
 	}
 
 	if (!strcmp("http.postbuffer", var)) {
-		http_post_buffer = git_config_int(var, value);
+		http_post_buffer = git_config_ssize_t(var, value);
 		if (http_post_buffer < LARGE_PACKET_MAX)
 			http_post_buffer = LARGE_PACKET_MAX;
 		return 0;
http.h +1 -1
index 02bccb7b0c..f7bd3b26b0 100644
@@ -111,7 +111,7 @@ extern struct curl_slist *http_copy_default_headers(void);
 extern long int git_curl_ipresolve;
 extern int active_requests;
 extern int http_is_verbose;
-extern size_t http_post_buffer;
+extern ssize_t http_post_buffer;
 extern struct credential http_auth;
 
 extern char curl_errorstr[CURL_ERROR_SIZE];
remote-curl.c +3 -3
index e953d06f66..69b4d71e4c 100644
@@ -614,7 +614,7 @@ static int post_rpc(struct rpc_state *rpc)
 		 * and we just need to send it.
 		 */
 		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
-		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
+		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) gzip_size);
 
 	} else if (use_gzip && 1024 < rpc->len) {
 		/* The client backend isn't giving us compressed data so
@@ -645,7 +645,7 @@ static int post_rpc(struct rpc_state *rpc)
 
 		headers = curl_slist_append(headers, "Content-Encoding: gzip");
 		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
-		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
+		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) gzip_size);
 
 		if (options.verbosity > 1) {
 			fprintf(stderr, "POST %s (gzip %lu to %lu bytes)\n",
@@ -658,7 +658,7 @@ static int post_rpc(struct rpc_state *rpc)
 		 * more normal Content-Length approach.
 		 */
 		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, rpc->buf);
-		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, rpc->len);
+		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) rpc->len);
 		if (options.verbosity > 1) {
 			fprintf(stderr, "POST %s (%lu bytes)\n",
 				rpc->service_name, (unsigned long)rpc->len);
Signature · 1 line
2.11.GIT
#1 lore raw
Quoted 103 lines · David Turner

Unfortunately, in order to push some large repos, 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.

---
 cache.h       |  1 +
 config.c      | 17 +++++++++++++++++
 http.c        |  4 ++--
 http.h        |  2 +-
 remote-curl.c |  6 +++---
 5 files changed, 24 insertions(+), 6 deletions(-)
cache.h +1 -0
index fbdf7a815a..5e6747dbb4 100644
@@ -1900,6 +1900,7 @@ extern int git_parse_maybe_bool(const char *);
 extern int git_config_int(const char *, const char *);
 extern int64_t git_config_int64(const char *, const char *);
 extern unsigned long git_config_ulong(const char *, const char *);
+extern ssize_t git_config_ssize_t(const char *, const char *);
 extern int git_config_bool_or_int(const char *, const char *, int *);
 extern int git_config_bool(const char *, const char *);
 extern int git_config_maybe_bool(const char *, const char *);
config.c +17 -0
index 1a4d85537b..de5b155a4e 100644
@@ -834,6 +834,15 @@ int git_parse_ulong(const char *value, unsigned long *ret)
 	return 1;
 }
 
+static int git_parse_ssize_t(const char *value, ssize_t *ret)
+{
+	ssize_t tmp;
+	if (!git_parse_signed(value, &tmp, maximum_signed_value_of_type(ssize_t)))
+		return 0;
+	*ret = tmp;
+	return 1;
+}
+
 NORETURN
 static void die_bad_number(const char *name, const char *value)
 {
@@ -892,6 +901,14 @@ unsigned long git_config_ulong(const char *name, const char *value)
 	return ret;
 }
 
+ssize_t git_config_ssize_t(const char *name, const char *value)
+{
+	ssize_t ret;
+	if (!git_parse_ssize_t(value, &ret))
+		die_bad_number(name, value);
+	return ret;
+}
+
 int git_parse_maybe_bool(const char *value)
 {
 	if (!value)
http.c +2 -2
index 96d84bbed3..22f8167ba2 100644
@@ -19,7 +19,7 @@ long int git_curl_ipresolve;
 #endif
 int active_requests;
 int http_is_verbose;
-size_t http_post_buffer = 16 * LARGE_PACKET_MAX;
+ssize_t http_post_buffer = 16 * LARGE_PACKET_MAX;
 
 #if LIBCURL_VERSION_NUM >= 0x070a06
 #define LIBCURL_CAN_HANDLE_AUTH_ANY
@@ -331,7 +331,7 @@ static int http_options(const char *var, const char *value, void *cb)
 	}
 
 	if (!strcmp("http.postbuffer", var)) {
-		http_post_buffer = git_config_int(var, value);
+		http_post_buffer = git_config_ssize_t(var, value);
 		if (http_post_buffer < LARGE_PACKET_MAX)
 			http_post_buffer = LARGE_PACKET_MAX;
 		return 0;
http.h +1 -1
index 02bccb7b0c..f7bd3b26b0 100644
@@ -111,7 +111,7 @@ extern struct curl_slist *http_copy_default_headers(void);
 extern long int git_curl_ipresolve;
 extern int active_requests;
 extern int http_is_verbose;
-extern size_t http_post_buffer;
+extern ssize_t http_post_buffer;
 extern struct credential http_auth;
 
 extern char curl_errorstr[CURL_ERROR_SIZE];
remote-curl.c +0 -0
index e953d06f66..69b4d71e4c 100644

remote-curl.c static int post_rpc(struct rpc_state *rpc) · line 617

Quoted 5 lines
remote-curl.c +1 -1
@@ -614,7 +614,7 @@ static int post_rpc(struct rpc_state *rpc)
 		 * and we just need to send it.
 		 */
 		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
-		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
+		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) gzip_size);

Is this cast safe, or can it silently truncate ?
Or is it more save to die() in this case, similar to ehat we do in git-compat-util.h?

static inline size_t xsize_t(off_t len)

{
	if (len > (size_t) len)
		die("Cannot handle files this big");
	return (size_t)len;
}
Quoted 22 lines
remote-curl.c +2 -2
 	} else if (use_gzip && 1024 < rpc->len) {
 		/* The client backend isn't giving us compressed data so
@@ -645,7 +645,7 @@ static int post_rpc(struct rpc_state *rpc)
 
 		headers = curl_slist_append(headers, "Content-Encoding: gzip");
 		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
-		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
+		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) gzip_size);
 
 		if (options.verbosity > 1) {
 			fprintf(stderr, "POST %s (gzip %lu to %lu bytes)\n",
@@ -658,7 +658,7 @@ static int post_rpc(struct rpc_state *rpc)
 		 * more normal Content-Length approach.
 		 */
 		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, rpc->buf);
-		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, rpc->len);
+		curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) rpc->len);
 		if (options.verbosity > 1) {
 			fprintf(stderr, "POST %s (%lu bytes)\n",
 				rpc->service_name, (unsigned long)rpc->len);
#2 lore raw
In reply to David Turner
Quoted 35 lines · David Turner

Unfortunately, in order to push some large repos, 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.

---
 cache.h       |  1 +
 config.c      | 17 +++++++++++++++++
 http.c        |  4 ++--
 http.h        |  2 +-
 remote-curl.c |  6 +++---
 5 files changed, 24 insertions(+), 6 deletions(-)
cache.h +1 -0
index fbdf7a815a..5e6747dbb4 100644
@@ -1900,6 +1900,7 @@ extern int git_parse_maybe_bool(const char *);
 extern int git_config_int(const char *, const char *);
 extern int64_t git_config_int64(const char *, const char *);
 extern unsigned long git_config_ulong(const char *, const char *);
+extern ssize_t git_config_ssize_t(const char *, const char *);
 extern int git_config_bool_or_int(const char *, const char *, int *);
 extern int git_config_bool(const char *, const char *);
 extern int git_config_maybe_bool(const char *, const char *);
config.c +0 -0
index 1a4d85537b..de5b155a4e 100644
@@ -834,6 +834,15 @@ int git_parse_ulong(const char *value, unsigned long *ret)
 	return 1;
 }

config.c int git_parse_ulong(const char *value, unsigned long *ret) · line 845

Quoted 10 lines
config.c +9 -0
 
+static int git_parse_ssize_t(const char *value, ssize_t *ret)
+{
+	ssize_t tmp;
+	if (!git_parse_signed(value, &tmp, maximum_signed_value_of_type(ssize_t)))
+		return 0;
+	*ret = tmp;
+	return 1;
+}
+

The previous version of this patch causes gcc to complain on a Linux 32bit build, like so:

CC config.o
config.c: In function ‘git_parse_ssize_t’:
config.c:840:31: warning: passing argument 2 of ‘git_parse_signed’ from incompatible pointer type [-Wincompatible-pointer-types]
if (!git_parse_signed(value, &tmp, maximum_signed_value_of_type(ssize_t)))

                               ^
config.c:753:12: note: expected ‘intmax_t * {aka long long int *}’ but argument is of type ‘ssize_t * {aka int *}’
 static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max)
            ^

... and I don't think this version would be any different (though I haven't tried).

ATB,
Ramsay Jones

#3 lore raw
Quoted 67 lines

-----Original Message-----
From: Ramsay Jones [mailto:[email protected]]
Sent: Monday, April 3, 2017 6:24 PM
To: David Turner <[email protected]>; [email protected]
Subject: Re: [PATCH v4] http.postbuffer: allow full range of ssize_t values

Quoted 5 lines · David Turner

Unfortunately, in order to push some large repos, 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

config.c int git_parse_ulong(const char *value, unsigned

Quoted 27 lines

buffer size.

---
 cache.h       |  1 +
 config.c      | 17 +++++++++++++++++
 http.c        |  4 ++--
 http.h        |  2 +-
 remote-curl.c |  6 +++---
 5 files changed, 24 insertions(+), 6 deletions(-)
cache.h +0 -0
index fbdf7a815a..5e6747dbb4 100644
@@ -1900,6 +1900,7 @@ extern int git_parse_maybe_bool(const char *);

extern int git_config_int(const char *, const char *); extern int64_t git_config_int64(const char *, const char *); extern unsigned long git_config_ulong(const char *, const char *);
+extern ssize_t git_config_ssize_t(const char *, const char *);
extern int git_config_bool_or_int(const char *, const char *, int *);
extern int git_config_bool(const char *, const char *); extern int git_config_maybe_bool(const char *, const char *); diff --git a/config.c b/config.c index 1a4d85537b..de5b155a4e 100644

config.c +0 -0
@@ -834,6 +834,15 @@ int git_parse_ulong(const char *value, unsigned

long *ret)

config.c int git_parse_ulong(const char *value, unsigned long *ret)

Quoted 6 lines
config.c +3 -0
 	return 1;
 }
 
+static int git_parse_ssize_t(const char *value, ssize_t *ret) {
+	ssize_t tmp;
+	if (!git_parse_signed(value, &tmp,

maximum_signed_value_of_type(ssize_t)))

config.c int git_parse_ulong(const char *value, unsigned long *ret) · line 845

Quoted 5 lines
config.c +5 -0
+		return 0;
+	*ret = tmp;
+	return 1;
+}
+

The previous version of this patch causes gcc to complain on a Linux 32bit build, like so:

CC config.o
config.c: In function ‘git_parse_ssize_t’:
config.c:840:31: warning: passing argument 2 of ‘git_parse_signed’ from incompatible pointer type [-Wincompatible-pointer-types]
if (!git_parse_signed(value, &tmp,
maximum_signed_value_of_type(ssize_t)))

Quoted 8 lines
                               ^
config.c:753:12: note: expected ‘intmax_t * {aka long long int *}’ but
argument is of type ‘ssize_t * {aka int *}’
 static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max)
            ^

... and I don't think this version would be any different (though I haven't tried).

So I guess that means tmp needs to be an intmax_t.