git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Set hard limit on delta chain depth

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Dec 5, 2011, 07:04 UTC
Message-ID
<1323068688-31481-1-git-send-email-pclouds@gmail.com>

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
Next: Erik Faye-Lund
Message 1 of 19 in “Set hard limit on delta chain depth”
  1. Set hard limit on delta chain depthNguyễn Thái Ngọc Duy, Dec 5, 2011
  2. Erik Faye-LundDec 6, 2011
  3. Nguyen Thai Ngoc DuyDec 6, 2011
  4. Erik Faye-LundDec 6, 2011
  5. Nguyen Thai Ngoc DuyDec 6, 2011
  6. Michael HaggertyDec 6, 2011
  7. Nguyen Thai Ngoc DuyDec 6, 2011
  8. Shawn PearceDec 6, 2011
  9. Jeff KingDec 6, 2011
  10. Junio C HamanoDec 6, 2011
  11. Nguyen Thai Ngoc DuyDec 6, 2011
  12. Junio C HamanoDec 10, 2011
  13. index-pack: eliminate unlimited recursion in get_delta_base()Nguyễn Thái Ngọc Duy, Dec 7, 2011
  14. Shawn PearceDec 8, 2011
  15. Nguyen Thai Ngoc DuyDec 8, 2011
  16. 1/2 index_pack: indent find_unresolved_detals one levelpclouds@gmail.com, Dec 8, 2011
  17. Junio C HamanoDec 9, 2011
  18. 2/2 index-pack: a naive attempt to flatten find_unresolved_deltaspclouds@gmail.com, Dec 8, 2011
  19. Shawn PearceDec 8, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.