|
14 | 14 | #include "packfile.h"
|
15 | 15 | #include "object-store-ll.h"
|
16 | 16 | #include "trace.h"
|
| 17 | +#include "environment.h" |
17 | 18 |
|
18 | 19 | struct traversal_context {
|
19 | 20 | struct rev_info *revs;
|
20 | 21 | show_object_fn show_object;
|
21 | 22 | show_commit_fn show_commit;
|
22 | 23 | void *show_data;
|
23 | 24 | struct filter *filter;
|
| 25 | + int depth; |
24 | 26 | };
|
25 | 27 |
|
26 | 28 | static void show_commit(struct traversal_context *ctx,
|
@@ -118,7 +120,9 @@ static void process_tree_contents(struct traversal_context *ctx,
|
118 | 120 | entry.path, oid_to_hex(&tree->object.oid));
|
119 | 121 | }
|
120 | 122 | t->object.flags |= NOT_USER_GIVEN;
|
| 123 | + ctx->depth++; |
121 | 124 | process_tree(ctx, t, base, entry.path);
|
| 125 | + ctx->depth--; |
122 | 126 | }
|
123 | 127 | else if (S_ISGITLINK(entry.mode))
|
124 | 128 | ; /* ignore gitlink */
|
@@ -156,6 +160,9 @@ static void process_tree(struct traversal_context *ctx,
|
156 | 160 | !revs->include_check_obj(&tree->object, revs->include_check_data))
|
157 | 161 | return;
|
158 | 162 |
|
| 163 | + if (ctx->depth > max_allowed_tree_depth) |
| 164 | + die("exceeded maximum allowed tree depth"); |
| 165 | + |
159 | 166 | failed_parse = parse_tree_gently(tree, 1);
|
160 | 167 | if (failed_parse) {
|
161 | 168 | if (revs->ignore_missing_links)
|
@@ -349,6 +356,7 @@ static void traverse_non_commits(struct traversal_context *ctx,
|
349 | 356 | if (!path)
|
350 | 357 | path = "";
|
351 | 358 | if (obj->type == OBJ_TREE) {
|
| 359 | + ctx->depth = 0; |
352 | 360 | process_tree(ctx, (struct tree *)obj, base, path);
|
353 | 361 | continue;
|
354 | 362 | }
|
|
0 commit comments