git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Set hard limit on delta chain depth
@ 2011-12-05  7:04 Nguyễn Thái Ngọc Duy
  2011-12-06 12:17 ` Erik Faye-Lund
  2011-12-06 15:06 ` Junio C Hamano
  0 siblings, 2 replies; 19+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2011-12-05  7:04 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Nguyễn Thái Ngọc Duy

Too deep delta chains can cause stack overflow in get_base_data(). Set
a hard limit so that index-pack does not run out of stack. Also stop
people from producing such a long delta chains using "pack-object
--depth=<too large>"

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 I used to make very long delta chains and triggered this in index-pack.
 I did not care reporting because it's my fault anyway. Think again,
 index-pack is called at server side and a malicious client can
 trigger this. This patch does not improve the situation much, but at
 least we won't get sigsegv at server side.

 builtin/index-pack.c   |   12 ++++++++++--
 builtin/pack-objects.c |    3 +++
 pack.h                 |    2 ++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 0945adb..cfb8cb2 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -504,13 +504,16 @@ static int is_delta_type(enum object_type type)
 	return (type == OBJ_REF_DELTA || type == OBJ_OFS_DELTA);
 }
 
-static void *get_base_data(struct base_data *c)
+static void *get_base_data_1(struct base_data *c, int depth)
 {
+	if (depth > MAX_DELTA_DEPTH)
+		die("index-pack: too long delta chain");
+
 	if (!c->data) {
 		struct object_entry *obj = c->obj;
 
 		if (is_delta_type(obj->type)) {
-			void *base = get_base_data(c->base);
+			void *base = get_base_data_1(c->base, depth + 1);
 			void *raw = get_data_from_pack(obj);
 			c->data = patch_delta(
 				base, c->base->size,
@@ -530,6 +533,11 @@ static void *get_base_data(struct base_data *c)
 	return c->data;
 }
 
+static void *get_base_data(struct base_data *c)
+{
+	return get_base_data_1(c, 0);
+}
+
 static void resolve_delta(struct object_entry *delta_obj,
 			  struct base_data *base, struct base_data *result)
 {
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 824ecee..85ee04b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2508,6 +2508,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 	if (keep_unreachable && unpack_unreachable)
 		die("--keep-unreachable and --unpack-unreachable are incompatible.");
 
+	if (depth > MAX_DELTA_DEPTH)
+		die("--depth exceeds %d", MAX_DELTA_DEPTH);
+
 	if (progress && all_progress_implied)
 		progress = 2;
 
diff --git a/pack.h b/pack.h
index 722a54e..b8f60c3 100644
--- a/pack.h
+++ b/pack.h
@@ -3,6 +3,8 @@
 
 #include "object.h"
 
+#define MAX_DELTA_DEPTH 128
+
 /*
  * Packed object header
  */
-- 
1.7.8.36.g69ee2

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2011-12-10  0:02 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-05  7:04 [PATCH] Set hard limit on delta chain depth Nguyễn Thái Ngọc Duy
2011-12-06 12:17 ` Erik Faye-Lund
2011-12-06 12:32   ` Nguyen Thai Ngoc Duy
2011-12-06 12:41     ` Erik Faye-Lund
2011-12-06 12:48       ` Nguyen Thai Ngoc Duy
2011-12-06 14:54   ` Michael Haggerty
2011-12-06 15:30     ` Nguyen Thai Ngoc Duy
2011-12-06 18:12       ` Shawn Pearce
2011-12-06 18:56         ` Jeff King
2011-12-06 15:06 ` Junio C Hamano
2011-12-06 15:45   ` Nguyen Thai Ngoc Duy
2011-12-10  0:02     ` Junio C Hamano
2011-12-07 17:50   ` [PATCH] index-pack: eliminate unlimited recursion in get_delta_base() Nguyễn Thái Ngọc Duy
2011-12-08  3:02     ` Shawn Pearce
2011-12-08 11:06       ` Nguyen Thai Ngoc Duy
2011-12-08 13:40       ` [PATCH 1/2] index_pack: indent find_unresolved_detals one level pclouds
2011-12-09 21:27         ` Junio C Hamano
     [not found]       ` <1323351638-4790-1-git-send-email-y>
2011-12-08 13:40         ` [PATCH 2/2] index-pack: a naive attempt to flatten find_unresolved_deltas pclouds
2011-12-08 16:42           ` Shawn Pearce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).