mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
Merge branch 'ps/upload-pack-oom-protection'
A broken or malicious "git fetch" can say that it has the same object for many many times, and the upload-pack serving it can exhaust memory storing them redundantly, which has been corrected. * ps/upload-pack-oom-protection: upload-pack: don't ACK non-commits repeatedly in protocol v2 t5530: modernize tests
This commit is contained in:
@@ -476,20 +476,17 @@ static void create_pack_file(struct upload_pack_data *pack_data,
|
||||
|
||||
static int do_got_oid(struct upload_pack_data *data, const struct object_id *oid)
|
||||
{
|
||||
int we_knew_they_have = 0;
|
||||
struct object *o = parse_object_with_flags(the_repository, oid,
|
||||
PARSE_OBJECT_SKIP_HASH_CHECK |
|
||||
PARSE_OBJECT_DISCARD_TREE);
|
||||
|
||||
if (!o)
|
||||
die("oops (%s)", oid_to_hex(oid));
|
||||
|
||||
if (o->type == OBJ_COMMIT) {
|
||||
struct commit_list *parents;
|
||||
struct commit *commit = (struct commit *)o;
|
||||
if (o->flags & THEY_HAVE)
|
||||
we_knew_they_have = 1;
|
||||
else
|
||||
o->flags |= THEY_HAVE;
|
||||
|
||||
if (!data->oldest_have || (commit->date < data->oldest_have))
|
||||
data->oldest_have = commit->date;
|
||||
for (parents = commit->parents;
|
||||
@@ -497,11 +494,13 @@ static int do_got_oid(struct upload_pack_data *data, const struct object_id *oid
|
||||
parents = parents->next)
|
||||
parents->item->object.flags |= THEY_HAVE;
|
||||
}
|
||||
if (!we_knew_they_have) {
|
||||
add_object_array(o, NULL, &data->have_obj);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
if (o->flags & THEY_HAVE)
|
||||
return 0;
|
||||
o->flags |= THEY_HAVE;
|
||||
|
||||
add_object_array(o, NULL, &data->have_obj);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int got_oid(struct upload_pack_data *data,
|
||||
|
||||
Reference in New Issue
Block a user