Skip to content

Commit ccbd34d

Browse files
committed
Merge branch 'ds/diff-lazy-fetch-with-name-only-fix' into next
Running "git diff" with "--name-only" and other options that allows us not to look at the blob contents, while objects that are lazily fetched from a promisor remote, caused use-after-free, which has been corrected. * ds/diff-lazy-fetch-with-name-only-fix: diff: avoid segfault with freed entries
2 parents 3b7c522 + 56d388e commit ccbd34d

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

diff.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7098,6 +7098,7 @@ static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
70987098
if (!diffopt->flags.no_index)
70997099
diffopt->skip_stat_unmatch++;
71007100
diff_free_filepair(p);
7101+
q->queue[i] = NULL;
71017102
}
71027103
}
71037104
free(q->queue);
@@ -7141,6 +7142,10 @@ void diff_queued_diff_prefetch(void *repository)
71417142

71427143
for (i = 0; i < q->nr; i++) {
71437144
struct diff_filepair *p = q->queue[i];
7145+
7146+
if (!p)
7147+
continue;
7148+
71447149
diff_add_if_missing(repo, &to_fetch, p->one);
71457150
diff_add_if_missing(repo, &to_fetch, p->two);
71467151
}

t/t4067-diff-partial-clone.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,41 @@ test_expect_success 'diff with rename detection batches blobs' '
132132
test_line_count = 1 done_lines
133133
'
134134

135+
test_expect_success 'diff succeeds even if entries are removed from queue' '
136+
test_when_finished "rm -rf server client trace" &&
137+
138+
test_create_repo server &&
139+
for l in a c e g i p
140+
do
141+
echo $l >server/$l &&
142+
git -C server add $l || return 1
143+
done &&
144+
git -C server commit -m x &&
145+
146+
for l in a e i
147+
do
148+
git -C server rm $l || return 1
149+
done &&
150+
151+
for l in b d f i
152+
do
153+
echo $l$l >server/$l &&
154+
git -C server add $l || return 1
155+
done &&
156+
git -C server commit -a -m x &&
157+
158+
test_config -C server uploadpack.allowfilter 1 &&
159+
test_config -C server uploadpack.allowanysha1inwant 1 &&
160+
git clone --filter=blob:limit=0 "file://$(pwd)/server" client &&
161+
162+
for file in $(ls client)
163+
do
164+
cat client/$file >$file &&
165+
mv $file client/$file || return 1
166+
done &&
167+
git -C client diff --name-only --relative HEAD^
168+
'
169+
135170
test_expect_success 'diff does not fetch anything if inexact rename detection is not needed' '
136171
test_when_finished "rm -rf server client trace" &&
137172

0 commit comments

Comments
 (0)