git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] fix hang in git fetch if pointed at a 0 length bundle

From
Brian Harring <ferringb@gmail.com>
Date
Jan 3, 2012, 13:46 UTC
Message-ID
<20120103134603.GA31034@localhost>
In-Reply-To
<20120103011352.GA13825@localhost>

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 <ferringb@chromium.org>
---
 bundle.c          |    4 ++--
 t/t5704-bundle.sh |    6 ++++++
 2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/bundle.c b/bundle.c
index 4742f27..b8acf3c 100644
--- a/bundle.c
+++ b/bundle.c
@@ -31,8 +31,8 @@ static int strbuf_readline_fd(struct strbuf *sb, int fd)
 	while (1) {
 		char ch;
 		ssize_t len = xread(fd, &ch, 1);
-		if (len < 0)
-			return -1;
+		if (len <= 0)
+			return len;
 		strbuf_addch(sb, ch);
 		if (ch == '\n')
 			break;
diff --git a/t/t5704-bundle.sh b/t/t5704-bundle.sh
index 728ccd8..4ae127d 100755
--- a/t/t5704-bundle.sh
+++ b/t/t5704-bundle.sh
@@ -53,4 +53,10 @@ test_expect_failure 'bundle --stdin <rev-list options>' '
 
 '
 
+test_expect_success 'empty bundle file is rejected' '
+
+    >empty-bundle && test_must_fail git fetch empty-bundle
+
+'
+
 test_done
-- 
1.7.8.2
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 6 in “fix hang in git fetch if pointed at a 0 length bundle”
  1. fix hang in git fetch if pointed at a 0 length bundleBrian Harring, Jan 3, 2012
  2. Johannes SixtJan 3, 2012
  3. Nguyen Thai Ngoc DuyJan 3, 2012
  4. Junio C HamanoJan 3, 2012
  5. fix hang in git fetch if pointed at a 0 length bundleBrian Harring, Jan 3, 2012
  6. Junio C HamanoJan 3, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.