Skip to content

Commit 54440e1

Browse files
ferringbgitster
authored andcommitted
fix hang in git fetch if pointed at a 0 length bundle
git-repo if interupted at the exact wrong time will generate zero length bundles- literal empty files. git-repo is wrong here, but git fetch shouldn't effectively spin loop if pointed at a zero length bundle. Signed-off-by: Brian Harring <[email protected]> Helped-by: Johannes Sixt Helped-by: Nguyen Thai Ngoc Duy Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3f778d commit 54440e1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

bundle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ static int strbuf_readline_fd(struct strbuf *sb, int fd)
3131
while (1) {
3232
char ch;
3333
ssize_t len = xread(fd, &ch, 1);
34-
if (len < 0)
35-
return -1;
34+
if (len <= 0)
35+
return len;
3636
strbuf_addch(sb, ch);
3737
if (ch == '\n')
3838
break;

t/t5704-bundle.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ test_expect_failure 'bundle --stdin <rev-list options>' '
5353
5454
'
5555

56+
test_expect_success 'empty bundle file is rejected' '
57+
58+
>empty-bundle && test_must_fail git fetch empty-bundle
59+
60+
'
61+
5662
test_done

0 commit comments

Comments
 (0)