diff options
author | Junio C Hamano <gitster@pobox.com> | 2024-03-08 00:59:42 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-03-08 00:59:42 +0100 |
commit | 56d608456000121f141a40c4501d41d712381674 (patch) | |
tree | 9c2885bf834dda29b5c9070f223445a5495ad0be /object.c | |
parent | Merge branch 'ps/reftable-repo-init-fix' (diff) | |
parent | upload-pack: free tree buffers after parsing (diff) | |
download | git-56d608456000121f141a40c4501d41d712381674.tar.xz git-56d608456000121f141a40c4501d41d712381674.zip |
Merge branch 'jk/upload-pack-bounded-resources'
Various parts of upload-pack has been updated to bound the resource
consumption relative to the size of the repository to protect from
abusive clients.
* jk/upload-pack-bounded-resources:
upload-pack: free tree buffers after parsing
upload-pack: use PARSE_OBJECT_SKIP_HASH_CHECK in more places
upload-pack: always turn off save_commit_buffer
upload-pack: disallow object-info capability by default
upload-pack: accept only a single packfile-uri line
upload-pack: use a strmap for want-ref lines
upload-pack: use oidset for deepen_not list
upload-pack: switch deepen-not list to an oid_array
upload-pack: drop separate v2 "haves" array
Diffstat (limited to 'object.c')
-rw-r--r-- | object.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -271,6 +271,7 @@ struct object *parse_object_with_flags(struct repository *r, enum parse_object_flags flags) { int skip_hash = !!(flags & PARSE_OBJECT_SKIP_HASH_CHECK); + int discard_tree = !!(flags & PARSE_OBJECT_DISCARD_TREE); unsigned long size; enum object_type type; int eaten; @@ -298,6 +299,17 @@ struct object *parse_object_with_flags(struct repository *r, return lookup_object(r, oid); } + /* + * If the caller does not care about the tree buffer and does not + * care about checking the hash, we can simply verify that we + * have the on-disk object with the correct type. + */ + if (skip_hash && discard_tree && + (!obj || obj->type == OBJ_TREE) && + oid_object_info(r, oid, NULL) == OBJ_TREE) { + return &lookup_tree(r, oid)->object; + } + buffer = repo_read_object_file(r, oid, &type, &size); if (buffer) { if (!skip_hash && @@ -311,6 +323,8 @@ struct object *parse_object_with_flags(struct repository *r, buffer, &eaten); if (!eaten) free(buffer); + if (discard_tree && type == OBJ_TREE) + free_tree_buffer((struct tree *)obj); return obj; } return NULL; |