1
0
mirror of https://github.com/git/git synced 2024-07-04 16:48:40 +00:00

receive-pack: allow a maximum input size to be specified

Receive-pack feeds its input to either index-pack or
unpack-objects, which will happily accept as many bytes as
a sender is willing to provide. Let's allow an arbitrary
cutoff point where we will stop writing bytes to disk.

Cleaning up what has already been written to disk is a
related problem that is not addressed by this patch.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2016-08-24 20:41:57 +02:00 committed by Junio C Hamano
parent 5ad2186733
commit c08db5a2d0
4 changed files with 76 additions and 0 deletions

View File

@ -2517,6 +2517,12 @@ receive.unpackLimit::
especially on slow filesystems. If not set, the value of
`transfer.unpackLimit` is used instead.
receive.maxInputSize::
If the size of the incoming pack stream is larger than this
limit, then git-receive-pack will error out, instead of
accepting the pack file. If not set or set to 0, then the size
is unlimited.
receive.denyDeletes::
If set to true, git-receive-pack will deny a ref update that deletes
the ref. Use this to prevent such a ref deletion via a push.

View File

@ -33,6 +33,9 @@ post-update hooks found in the Documentation/howto directory.
option, which tells it if updates to a ref should be denied if they
are not fast-forwards.
A number of other receive.* config options are available to tweak
its behavior, see linkgit:git-config[1].
OPTIONS
-------
<directory>::

View File

@ -46,6 +46,7 @@ static int transfer_unpack_limit = -1;
static int advertise_atomic_push = 1;
static int advertise_push_options;
static int unpack_limit = 100;
static off_t max_input_size;
static int report_status;
static int use_sideband;
static int use_atomic;
@ -212,6 +213,11 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
return 0;
}
if (strcmp(var, "receive.maxinputsize") == 0) {
max_input_size = git_config_int64(var, value);
return 0;
}
return git_default_config(var, value, cb);
}
@ -1648,6 +1654,9 @@ static const char *unpack(int err_fd, struct shallow_info *si)
if (fsck_objects)
argv_array_pushf(&child.args, "--strict%s",
fsck_msg_types.buf);
if (max_input_size)
argv_array_pushf(&child.args, "--max-input-size=%"PRIuMAX,
(uintmax_t)max_input_size);
child.no_stdout = 1;
child.err = err_fd;
child.git_cmd = 1;
@ -1676,6 +1685,9 @@ static const char *unpack(int err_fd, struct shallow_info *si)
fsck_msg_types.buf);
if (!reject_thin)
argv_array_push(&child.args, "--fix-thin");
if (max_input_size)
argv_array_pushf(&child.args, "--max-input-size=%"PRIuMAX,
(uintmax_t)max_input_size);
child.out = -1;
child.err = err_fd;
child.git_cmd = 1;

55
t/t5546-receive-limits.sh Executable file
View File

@ -0,0 +1,55 @@
#!/bin/sh
test_description='check receive input limits'
. ./test-lib.sh
# Let's run tests with different unpack limits: 1 and 10000
# When the limit is 1, `git receive-pack` will call `git index-pack`.
# When the limit is 10000, `git receive-pack` will call `git unpack-objects`.
test_pack_input_limit () {
case "$1" in
index) unpack_limit=1 ;;
unpack) unpack_limit=10000 ;;
esac
test_expect_success 'prepare destination repository' '
rm -fr dest &&
git --bare init dest
'
test_expect_success "set unpacklimit to $unpack_limit" '
git --git-dir=dest config receive.unpacklimit "$unpack_limit"
'
test_expect_success 'setting receive.maxInputSize to 512 rejects push' '
git --git-dir=dest config receive.maxInputSize 512 &&
test_must_fail git push dest HEAD
'
test_expect_success 'bumping limit to 4k allows push' '
git --git-dir=dest config receive.maxInputSize 4k &&
git push dest HEAD
'
test_expect_success 'prepare destination repository (again)' '
rm -fr dest &&
git --bare init dest
'
test_expect_success 'lifting the limit allows push' '
git --git-dir=dest config receive.maxInputSize 0 &&
git push dest HEAD
'
}
test_expect_success "create known-size (1024 bytes) commit" '
test-genrandom foo 1024 >one-k &&
git add one-k &&
test_commit one-k
'
test_pack_input_limit index
test_pack_input_limit unpack
test_done