From e58e57e49eb990e38df19628a744c71b44397ef1 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 20 Feb 2013 14:54:57 -0500 Subject: [PATCH] upload-pack: do not add duplicate objects to shallow list When the client tells us it has a shallow object via "shallow ", we make sure we have the object, mark it with a flag, then add it to a dynamic array of shallow objects. This means that a client can get us to allocate arbitrary amounts of memory just by flooding us with shallow lines (whether they have the objects or not). You can demonstrate it easily with: yes '0035shallow e83c5163316f89bfbde7d9ab23ca2e25604af290' | git-upload-pack git.git We already protect against duplicates in want lines by checking if our flag is already set; let's do the same thing here. Note that a client can still get us to allocate some amount of memory by marking every object in the repo as "shallow" (or "want"). But this at least bounds it with the number of objects in the repository, which is not under the control of an upload-pack client. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- upload-pack.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index b058e8de50..bd6f25519c 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -603,8 +603,10 @@ static void receive_needs(void) die("did not find object for %s", line); if (object->type != OBJ_COMMIT) die("invalid shallow object %s", sha1_to_hex(sha1)); - object->flags |= CLIENT_SHALLOW; - add_object_array(object, NULL, &shallows); + if (!(object->flags & CLIENT_SHALLOW)) { + object->flags |= CLIENT_SHALLOW; + add_object_array(object, NULL, &shallows); + } continue; } if (!prefixcmp(line, "deepen ")) { -- 2.11.4.GIT