Skip to content

Commit 391c3a1

Browse files
derrickstoleegitster
authored andcommitted
sparse-checkout: fix OOM error with mixed patterns
Add a test to t1091-sparse-checkout-builtin.sh that would result in an infinite loop and out-of-memory error before this change. The issue relies on having non-cone-mode patterns while trying to modify the patterns in cone-mode. The fix is simple, allowing us to break from the loop when the input path does not contain a slash, as the "dir" pattern we added does not. This is only a fix to the critical out-of-memory error. A better response to such a strange state will follow in a later change. Reported-by: Calbabreaker <[email protected]> Helped-by: Taylor Blau <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a481d43 commit 391c3a1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

builtin/sparse-checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat
483483
char *oldpattern = e->pattern;
484484
size_t newlen;
485485

486-
if (slash == e->pattern)
486+
if (!slash || slash == e->pattern)
487487
break;
488488

489489
newlen = slash - e->pattern;

t/t1091-sparse-checkout-builtin.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ test_expect_success 'clone --sparse' '
103103
check_files clone a
104104
'
105105

106+
test_expect_success 'switching to cone mode with non-cone mode patterns' '
107+
git init bad-patterns &&
108+
(
109+
cd bad-patterns &&
110+
git sparse-checkout init &&
111+
git sparse-checkout add dir &&
112+
git config core.sparseCheckoutCone true &&
113+
git sparse-checkout add dir
114+
)
115+
'
116+
106117
test_expect_success 'interaction with clone --no-checkout (unborn index)' '
107118
git clone --no-checkout "file://$(pwd)/repo" clone_no_checkout &&
108119
git -C clone_no_checkout sparse-checkout init --cone &&

0 commit comments

Comments
 (0)