7
7
#include "hash.h"
8
8
#include "tree.h"
9
9
#include "tree-walk.h"
10
+ #include "environment.h"
10
11
11
12
/*
12
13
* Some mode bits are also used internally for computations.
45
46
static struct combine_diff_path * ll_diff_tree_paths (
46
47
struct combine_diff_path * p , const struct object_id * oid ,
47
48
const struct object_id * * parents_oid , int nparent ,
48
- struct strbuf * base , struct diff_options * opt );
49
+ struct strbuf * base , struct diff_options * opt ,
50
+ int depth );
49
51
static void ll_diff_tree_oid (const struct object_id * old_oid ,
50
52
const struct object_id * new_oid ,
51
53
struct strbuf * base , struct diff_options * opt );
@@ -196,7 +198,7 @@ static struct combine_diff_path *path_appendnew(struct combine_diff_path *last,
196
198
static struct combine_diff_path * emit_path (struct combine_diff_path * p ,
197
199
struct strbuf * base , struct diff_options * opt , int nparent ,
198
200
struct tree_desc * t , struct tree_desc * tp ,
199
- int imin )
201
+ int imin , int depth )
200
202
{
201
203
unsigned short mode ;
202
204
const char * path ;
@@ -302,7 +304,8 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
302
304
303
305
strbuf_add (base , path , pathlen );
304
306
strbuf_addch (base , '/' );
305
- p = ll_diff_tree_paths (p , oid , parents_oid , nparent , base , opt );
307
+ p = ll_diff_tree_paths (p , oid , parents_oid , nparent , base , opt ,
308
+ depth + 1 );
306
309
FAST_ARRAY_FREE (parents_oid , nparent );
307
310
}
308
311
@@ -423,12 +426,16 @@ static inline void update_tp_entries(struct tree_desc *tp, int nparent)
423
426
static struct combine_diff_path * ll_diff_tree_paths (
424
427
struct combine_diff_path * p , const struct object_id * oid ,
425
428
const struct object_id * * parents_oid , int nparent ,
426
- struct strbuf * base , struct diff_options * opt )
429
+ struct strbuf * base , struct diff_options * opt ,
430
+ int depth )
427
431
{
428
432
struct tree_desc t , * tp ;
429
433
void * ttree , * * tptree ;
430
434
int i ;
431
435
436
+ if (depth > max_allowed_tree_depth )
437
+ die ("exceeded maximum allowed tree depth" );
438
+
432
439
FAST_ARRAY_ALLOC (tp , nparent );
433
440
FAST_ARRAY_ALLOC (tptree , nparent );
434
441
@@ -522,7 +529,7 @@ static struct combine_diff_path *ll_diff_tree_paths(
522
529
523
530
/* D += {δ(t,pi) if pi=p[imin]; "+a" if pi > p[imin]} */
524
531
p = emit_path (p , base , opt , nparent ,
525
- & t , tp , imin );
532
+ & t , tp , imin , depth );
526
533
527
534
skip_emit_t_tp :
528
535
/* t↓, ∀ pi=p[imin] pi↓ */
@@ -534,7 +541,7 @@ static struct combine_diff_path *ll_diff_tree_paths(
534
541
else if (cmp < 0 ) {
535
542
/* D += "+t" */
536
543
p = emit_path (p , base , opt , nparent ,
537
- & t , /*tp=*/ NULL , -1 );
544
+ & t , /*tp=*/ NULL , -1 , depth );
538
545
539
546
/* t↓ */
540
547
update_tree_entry (& t );
@@ -550,7 +557,7 @@ static struct combine_diff_path *ll_diff_tree_paths(
550
557
}
551
558
552
559
p = emit_path (p , base , opt , nparent ,
553
- /*t=*/ NULL , tp , imin );
560
+ /*t=*/ NULL , tp , imin , depth );
554
561
555
562
skip_emit_tp :
556
563
/* ∀ pi=p[imin] pi↓ */
@@ -572,7 +579,7 @@ struct combine_diff_path *diff_tree_paths(
572
579
const struct object_id * * parents_oid , int nparent ,
573
580
struct strbuf * base , struct diff_options * opt )
574
581
{
575
- p = ll_diff_tree_paths (p , oid , parents_oid , nparent , base , opt );
582
+ p = ll_diff_tree_paths (p , oid , parents_oid , nparent , base , opt , 0 );
576
583
577
584
/*
578
585
* free pre-allocated last element, if any
0 commit comments