"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
add per object-type size limits to gotd.conf
To:
gameoftrees@openbsd.org
Date:
Wed, 25 Nov 2026 11:13:16 +0100

Download raw body.

Thread
  • Stefan Sperling:

    add per object-type size limits to gotd.conf

This patch adds more fine-grained control over object size limits.

The main use case is that the size limit imposed on blobs can now
differ from the limit imposed on commits, tags, and trees, allowing
gotd to block megabyte-sized commit log messages while still letting
large files go through.

ok?

 
M  gotd/gotd.c                        |    7+   1-
M  gotd/gotd.conf.5                   |   19+   3-
M  gotd/gotd.h                        |    9+   0-
M  gotd/parse.y                       |   21+   1-
M  gotd/repo_write.c                  |   60+  15-
M  regress/gotd/Makefile              |    4+   1-
M  regress/gotd/repo_write_limits.sh  |  181+  12-

7 files changed, 301 insertions(+), 33 deletions(-)

commit - 34474ee2f8526f9930df666207c75082fa7ea8d815c856487623025af6fde0d6
commit + c66166caa263c0b7d9f8e9b817b4ceb5b35ae9ed21b883eac703a81d8d122eef
blob - 020cf9a5498c6814576b58635fa4a68d35a7a334504e141e6eba52992d2d2b9f
blob + edf433f1c0a77d407cde2827254ac1acfd15c68564eda85f9cbaa17b0aea57a4
--- gotd/gotd.c	
+++ gotd/gotd.c	
@@ -2918,11 +2918,17 @@ send_repo_limits(struct gotd_imsgev *iev, const char *
 	if (repo == NULL)
 		return got_error(GOT_ERR_NOT_GIT_REPO);
 
-	if (repo->object_size == 0)
+	if (repo->object_size == 0 && repo->blob_size == 0 &&
+	    repo->tree_size == 0 && repo->commit_size == 0 &&
+	    repo->tag_size == 0)
 		return NULL;
 
 	memset(&ilimits, 0, sizeof(ilimits));
 	ilimits.object_size = repo->object_size;
+	ilimits.blob_size = repo->blob_size;
+	ilimits.tree_size = repo->tree_size;
+	ilimits.commit_size = repo->commit_size;
+	ilimits.tag_size = repo->tag_size;
 
 	if (gotd_imsg_compose_event(iev, GOTD_IMSG_REPO_LIMITS,
 	    GOTD_PROC_GOTD, -1, &ilimits, sizeof(ilimits)) == -1)
blob - 4e8295ea6c4e4f01fe67e6a1745b3472decdca9cdf04acd3d1eae6ad07d1df1b
blob + 9d342de98fa84013d7a946218816e5c54ebb41db6ceb287d94e3e32574670be9
--- gotd/gotd.conf.5	
+++ gotd/gotd.conf.5	
@@ -185,10 +185,26 @@ may be given in bytes or with a suffix of
 or
 .Sq T
 for kilobytes, megabytes, gigabytes, or terabytes, respectively.
-By default, file sizes are not limited.
+By default, object sizes are not limited.
 .Pp
-Only files contained in a new pack are checked.
-Files which already exist in the repository are not affected.
+Only objects contained in a new pack are checked.
+Objects which already exist in the repository are not affected.
+.It Ic limit blobsize Ar size
+Like
+.Ic objectsize ,
+but only applies to blob objects.
+.It Ic limit treesize Ar size
+Like
+.Ic objectsize ,
+but only applies to tree objects.
+.It Ic limit commitsize Ar size
+Like
+.Ic objectsize ,
+but only applies to commit objects.
+.It Ic limit tagsize Ar size
+Like
+.Ic objectsize ,
+but only applies to tag objects.
 .It Ic path Ar path
 Set the path to the Git repository.
 Must be specified.
blob - a8f6a30ee94af344ba046c94d5affa640694023bb77e93ba761994dc0eaaae44
blob + 74b8bab00a51a0a519a6a3290b30a238035e4f54d035b4155c86b16216cebc77
--- gotd/gotd.h	
+++ gotd/gotd.h	
@@ -151,7 +151,12 @@ struct gotd_repo {
 	size_t num_notification_ref_namespaces;
 	struct gotd_notification_targets notification_targets;
 
+	/* Object size limits enforced while receiving pack files. */
 	uint64_t object_size;
+	uint64_t blob_size;
+	uint64_t tree_size;
+	uint64_t commit_size;
+	uint64_t tag_size;
 };
 TAILQ_HEAD(gotd_repolist, gotd_repo);
 
@@ -609,6 +614,10 @@ struct gotd_imsg_pathlist {
 /* Structure for GOTD_IMSG_REPO_LIMITS. */
 struct gotd_imsg_repo_limits {
 	uint64_t object_size;
+	uint64_t blob_size;
+	uint64_t tree_size;
+	uint64_t commit_size;
+	uint64_t tag_size;
 };
 
 /*
blob - f81a13c425aaf72e3f7b5e35a83252876af2c86f3192024742b8cadc151ac362
blob + ff3d92fd516abce0731f42cd93370a502b179adae350bb897d5f62a2cc57718f
--- gotd/parse.y	
+++ gotd/parse.y	
@@ -135,7 +135,7 @@ typedef struct {
 %token	PATH ERROR LISTEN ON USER REPOSITORY PERMIT DENY
 %token	RO RW CONNECTION LIMIT REQUEST TIMEOUT
 %token	PROTECT NAMESPACE BRANCH TAG REFERENCE RELAY PORT
-%token	OBJECTSIZE
+%token	OBJECTSIZE BLOBSIZE TREESIZE COMMITSIZE TAGSIZE
 %token	NOTIFY EMAIL FROM REPLY TO URL INSECURE HMAC AUTH AUTHENTICATED AT
 
 %token	<v.string>	STRING
@@ -899,6 +899,22 @@ repoopts1	: PATH STRING {
 			if (gotd_proc_id == GOTD_PROC_GOTD)
 				new_repo->object_size = $3;
 		}
+		| LIMIT BLOBSIZE size {
+			if (gotd_proc_id == GOTD_PROC_GOTD)
+				new_repo->blob_size = $3;
+		}
+		| LIMIT TREESIZE size {
+			if (gotd_proc_id == GOTD_PROC_GOTD)
+				new_repo->tree_size = $3;
+		}
+		| LIMIT COMMITSIZE size {
+			if (gotd_proc_id == GOTD_PROC_GOTD)
+				new_repo->commit_size = $3;
+		}
+		| LIMIT TAGSIZE size {
+			if (gotd_proc_id == GOTD_PROC_GOTD)
+				new_repo->tag_size = $3;
+		}
 		| protect
 		| notify
 		;
@@ -951,7 +967,9 @@ lookup(char *s)
 		{ "at",				AT },
 		{ "auth",			AUTH },
 		{ "authenticated",		AUTHENTICATED },
+		{ "blobsize",			BLOBSIZE },
 		{ "branch",			BRANCH },
+		{ "commitsize",			COMMITSIZE },
 		{ "connection",			CONNECTION },
 		{ "deny",			DENY },
 		{ "email",			EMAIL },
@@ -976,8 +994,10 @@ lookup(char *s)
 		{ "ro",				RO },
 		{ "rw",				RW },
 		{ "tag",			TAG },
+		{ "tagsize",			TAGSIZE },
 		{ "timeout",			TIMEOUT },
 		{ "to",				TO },
+		{ "treesize",			TREESIZE },
 		{ "url",			URL },
 		{ "user",			USER },
 	};
blob - a054d7b42a1a432d924de5ca851ed32d21f5f512fa2d7315d7c1df1c4c234115
blob + 63cf646d37e3f95368b91173a6a9ac0a9e4517c7b01aa5e92692f5801f5e8f38
--- gotd/repo_write.c	
+++ gotd/repo_write.c	
@@ -68,6 +68,14 @@
 #define nitems(_a)	(sizeof((_a)) / sizeof((_a)[0]))
 #endif
 
+struct size_limits {
+	uint64_t object_size;
+	uint64_t blob_size;
+	uint64_t tree_size;
+	uint64_t commit_size;
+	uint64_t tag_size;
+};
+
 static struct repo_write {
 	pid_t pid;
 	const char *title;
@@ -81,7 +89,7 @@ static struct repo_write {
 	struct got_pathlist_head protected_tag_namespaces;
 	struct got_pathlist_head protected_branch_namespaces;
 	struct got_pathlist_head protected_branches;
-	uint64_t object_size;
+	struct size_limits limits;
 	struct {
 		FILE *f1;
 		FILE *f2;
@@ -774,24 +782,57 @@ pack_index_progress(void *arg, uint32_t nobj_total, ui
 }
 
 static const struct got_error *
+check_limit(struct got_object_id *id, const char *label, uint64_t size,
+    uint64_t limit)
+{
+	const struct got_error *err;
+	char *id_str;
+
+	if (size <= limit)
+		return NULL;
+
+	err = got_object_id_str(&id_str, id);
+	if (err)
+		return err;
+
+	err = got_error_fmt(GOT_ERR_OBJ_TOO_LARGE,
+	    "%sobject %s exceeds size limit of %llu bytes",
+	    label, id_str, limit);
+	free(id_str);
+	return err;
+}
+
+static const struct got_error *
 verify_packed_object(void *arg, struct got_object_id *id, int obj_type,
     uint64_t size)
 {
-	const struct got_error *err;
-	char *id_str;
-	uint64_t *limit = arg;
+	struct size_limits *limits = arg;
 
-	if (*limit == 0 || size <= *limit)
+	switch (obj_type) {
+	case GOT_OBJ_TYPE_BLOB:
+		if (limits->blob_size == 0)
+			break;
+		return check_limit(id, "blob ", size, limits->blob_size);
+	case GOT_OBJ_TYPE_TREE:
+		if (limits->tree_size == 0)
+			break;
+		return check_limit(id, "tree ", size, limits->tree_size);
+	case GOT_OBJ_TYPE_COMMIT:
+		if (limits->commit_size == 0)
+			break;
+		return check_limit(id, "commit ", size, limits->commit_size);
+	case GOT_OBJ_TYPE_TAG:
+		if (limits->tag_size == 0)
+			break;
+		return check_limit(id, "tag ", size, limits->tag_size);
+	default:
+		break;
+	}
+
+	if (limits->object_size == 0)
 		return NULL;
 
-	err = got_object_id_str(&id_str, id);
-	if (err)
-		return err;
-
-	err = got_error_fmt(GOT_ERR_OBJ_TOO_LARGE,
-	    "object %s exceeds size limit of %llu bytes", id_str, *limit);
-	free(id_str);
-	return err;
+	return check_limit(id, "", size, limits->object_size);
 }
 
 static const struct got_error *
@@ -1385,7 +1426,7 @@ recv_packfile(int *have_packfile, struct imsg *imsg)
 	err = got_pack_index(pack, client->packidx_fd,
 	    tempfiles[0], tempfiles[1], tempfiles[2], &id,
 	    pack_index_progress, NULL,
-	    verify_packed_object, &repo_write.object_size, &rl);
+	    verify_packed_object, &repo_write.limits, &rl);
 	if (err)
 		goto done;
 	log_debug("done indexing pack");
@@ -2976,7 +3017,11 @@ repo_write_dispatch(int fd, short event, void *arg)
 				break;
 			}
 			memcpy(&ilimits, imsg.data, sizeof(ilimits));
-			repo_write.object_size = ilimits.object_size;
+			repo_write.limits.object_size = ilimits.object_size;
+			repo_write.limits.blob_size = ilimits.blob_size;
+			repo_write.limits.tree_size = ilimits.tree_size;
+			repo_write.limits.commit_size = ilimits.commit_size;
+			repo_write.limits.tag_size = ilimits.tag_size;
 			break;
 		}
 		case GOTD_IMSG_CONNECT_REPO_CHILD:
blob - 920e6664d9537cf1fa9458b485afd10cd1eaf76e72edda1302931521e7c0bafe
blob + 8f3ab2f1573c955edb589c19d5d279875f865086b9d2b19f42aa8f4be6e49692
--- regress/gotd/Makefile	
+++ regress/gotd/Makefile	
@@ -192,7 +192,10 @@ start_gotd_rw_limits: ensure_root
 	@echo 'repository "test-repo" {' >> $(PWD)/gotd.conf
 	@echo '    path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf
 	@echo '    permit rw $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf
-	@echo '    limit objectsize 64K' >> $(PWD)/gotd.conf
+	@echo '    limit blobsize 64K' >> $(PWD)/gotd.conf
+	@echo '    limit commitsize 16K' >> $(PWD)/gotd.conf
+	@echo '    limit treesize 8K' >> $(PWD)/gotd.conf
+	@echo '    limit objectsize 1K' >> $(PWD)/gotd.conf
 	@echo "}" >> $(PWD)/gotd.conf
 	@$(GOTD_TRAP); $(GOTD_START_CMD)
 	@$(GOTD_TRAP); sleep .5
blob - ff0355e18bc644a504050a7f8e231557901404054aac0a926fa4f11e42e0494a
blob + 598779a6ac114beb9ac4f153a812d033d2a242ed4d0c93b2750f208e304d84ca
--- regress/gotd/repo_write_limits.sh	
+++ regress/gotd/repo_write_limits.sh	
@@ -14,9 +14,6 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-# The gotd configuration used by these tests sets:
-#	limit objectsize 64K
-
 . ../cmdline/common.sh
 . ./common.sh
 
@@ -52,8 +49,8 @@ check_server_main() {
 	return 0
 }
 
-test_send_file_too_large() {
-	local testroot=`test_init send_file_too_large 1`
+test_send_blob_too_large() {
+	local testroot=`test_init send_blob_too_large 1`
 
 	got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
 	ret=$?
@@ -72,7 +69,7 @@ test_send_file_too_large() {
 		return 1
 	fi
 
-	# 128K exceeds the 64K object size limit
+	# 128K exceeds the 64K blob size limit
 	make_random_file $testroot/wt/large 128
 	(cd $testroot/wt && got add large >/dev/null)
 	(cd $testroot/wt && got commit -m 'add large file' >/dev/null)
@@ -91,7 +88,7 @@ test_send_file_too_large() {
 		return 1
 	fi
 
-	if ! egrep -q '(gotsh|got-send-pack): object [0-9a-f]+ exceeds size limit of 65536 bytes' \
+	if ! egrep -q '(gotsh|got-send-pack): blob object [0-9a-f]+ exceeds size limit of 65536 bytes' \
 		$testroot/stderr; then
 		echo -n "error message unexpected or missing: " >&2
 		cat $testroot/stderr >&2
@@ -104,8 +101,8 @@ test_send_file_too_large() {
 	test_done "$testroot" $ret
 }
 
-test_send_file_too_large_delta() {
-	local testroot=`test_init send_file_too_large_delta 1`
+test_send_blob_too_large_delta() {
+	local testroot=`test_init send_blob_too_large_delta 1`
 
 	got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
 	ret=$?
@@ -155,7 +152,7 @@ test_send_file_too_large_delta() {
 		return 1
 	fi
 
-	if ! egrep -q '(gotsh|got-send-pack): object [0-9a-f]+ exceeds size limit of 65536 bytes' \
+	if ! egrep -q '(gotsh|got-send-pack): blob object [0-9a-f]+ exceeds size limit of 65536 bytes' \
 		$testroot/stderr; then
 		echo -n "error message unexpected or missing: " >&2
 		cat $testroot/stderr >&2
@@ -168,6 +165,175 @@ test_send_file_too_large_delta() {
 	test_done "$testroot" $ret
 }
 
+test_send_tree_too_large() {
+	local testroot=`test_init send_tree_too_large 1`
+
+	got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got clone failed unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+	local old_commit_id=`git_show_head $testroot/repo-clone`
+
+	got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got checkout failed unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	for i in `seq 50`; do
+		longfilename=`perl -e "print \"a$i\"x50"`
+		touch $testroot/wt/$longfilename
+		
+	done
+	(cd $testroot/wt && got add -R * >/dev/null)
+	(cd $testroot/wt && got commit -m 'add large tree' >/dev/null)
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got commit failed unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	got send -q -r $testroot/repo-clone 2> $testroot/stderr
+	ret=$?
+	if [ $ret -eq 0 ]; then
+		echo "got send succeeded unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	if ! egrep -q '(gotsh|got-send-pack): tree object [0-9a-f]+ exceeds size limit of 8192 bytes' \
+		$testroot/stderr; then
+		echo -n "error message unexpected or missing: " >&2
+		cat $testroot/stderr >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	check_server_main $testroot $old_commit_id
+	ret=$?
+	test_done "$testroot" $ret
+}
+
+test_send_commit_too_large() {
+	local testroot=`test_init send_commit_too_large 1`
+
+	got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got clone failed unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+	local old_commit_id=`git_show_head $testroot/repo-clone`
+
+	got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got checkout failed unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	make_random_file $testroot/large-bin 16
+	hexdump $testroot/large-bin > $testroot/large-message
+	echo "new" > $testroot/wt/new
+	(cd $testroot/wt && got add new >/dev/null)
+	(cd $testroot/wt && got commit -N -F $testroot/large-message >/dev/null)
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got commit failed unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	got send -q -r $testroot/repo-clone 2> $testroot/stderr
+	ret=$?
+	if [ $ret -eq 0 ]; then
+		echo "got send succeeded unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	if ! egrep -q '(gotsh|got-send-pack): commit object [0-9a-f]+ exceeds size limit of 16384 bytes' \
+		$testroot/stderr; then
+		echo -n "error message unexpected or missing: " >&2
+		cat $testroot/stderr >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	check_server_main $testroot $old_commit_id
+	ret=$?
+	test_done "$testroot" $ret
+}
+
+test_send_object_too_large() {
+	local testroot=`test_init send_object_too_large 1`
+
+	got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got clone failed unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+	local old_commit_id=`git_show_head $testroot/repo-clone`
+
+	got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got checkout failed unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	echo "new" > $testroot/wt/new
+	(cd $testroot/wt && got add new >/dev/null)
+	(cd $testroot/wt && got commit -m "new file" >/dev/null)
+
+	cat > $testroot/editor.sh <<EOF
+#!/bin/sh
+perl -e 'print "a"x1048' > "\$1"
+EOF
+	chmod +x $testroot/editor.sh
+
+	# Tag objects are covered by the generic objectsize limit in this test.
+	env EDITOR="$testroot/editor.sh" got tag \
+		-r $testroot/repo-clone 1.0 >/dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got tag failed unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	got send -q -r $testroot/repo-clone -t 1.0 2> $testroot/stderr
+	ret=$?
+	if [ $ret -eq 0 ]; then
+		echo "got send succeeded unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	if ! egrep -q '(gotsh|got-send-pack): object [0-9a-f]+ exceeds size limit of 1024 bytes' \
+		$testroot/stderr; then
+		echo -n "error message unexpected or missing: " >&2
+		cat $testroot/stderr >&2
+		test_done "$testroot" 1
+		return 1
+	fi
+
+	check_server_main $testroot $old_commit_id
+	ret=$?
+	test_done "$testroot" $ret
+}
+
 test_send_within_limit() {
 	local testroot=`test_init send_within_limit 1`
 
@@ -214,6 +380,9 @@ test_send_within_limit() {
 }
 
 test_parseargs "$@"
-run_test test_send_file_too_large
-run_test test_send_file_too_large_delta
+run_test test_send_blob_too_large
+run_test test_send_blob_too_large_delta
+run_test test_send_tree_too_large
+run_test test_send_commit_too_large
+run_test test_send_object_too_large
 run_test test_send_within_limit