Skip to content

Commit 53d8afa

Browse files
j6tgitster
authored andcommitted
rerere forget: grok files containing NUL
Using 'git rerere forget .' after a merge that involved binary files runs into an infinite loop if the binary file contains a zero byte. Replace a strchrnul by memchr because the former does not make progress as soon as the NUL is encountered. Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1599999 commit 53d8afa

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

rerere.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,10 @@ static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
284284
strbuf_release(sb);
285285
if (!io->input.len)
286286
return -1;
287-
ep = strchrnul(io->input.buf, '\n');
288-
if (*ep == '\n')
287+
ep = memchr(io->input.buf, '\n', io->input.len);
288+
if (!ep)
289+
ep = io->input.buf + io->input.len;
290+
else if (*ep == '\n')
289291
ep++;
290292
len = ep - io->input.buf;
291293
strbuf_add(sb, io->input.buf, len);

t/t2030-unresolve-info.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ prime_resolve_undo () {
4444

4545
test_expect_success setup '
4646
mkdir fi &&
47+
printf "a\0a" >binary &&
48+
git add binary &&
4749
test_commit initial fi/le first &&
4850
git branch side &&
4951
git branch another &&
52+
printf "a\0b" >binary &&
53+
git add binary &&
5054
test_commit second fi/le second &&
5155
git checkout side &&
5256
test_commit third fi/le third &&
@@ -167,4 +171,12 @@ test_expect_success 'rerere and rerere forget (subdirectory)' '
167171
test_cmp expect actual
168172
'
169173

174+
test_expect_success 'rerere forget (binary)' '
175+
git checkout -f side &&
176+
printf "a\0c" >binary &&
177+
git commit -a -m binary &&
178+
test_must_fail git merge second &&
179+
git rerere forget binary
180+
'
181+
170182
test_done

0 commit comments

Comments
 (0)