git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Sixt <j.sixt@eudaptics.com>
To: git@vger.kernel.org
Cc: Johannes Sixt <johannes.sixt@telecom.at>
Subject: [PATCH] Catch errors when writing an index that contains invalid objects.
Date: Mon, 13 Nov 2006 13:50:00 +0000 (UTC)	[thread overview]
Message-ID: <11634257782215-git-send-email-j.sixt@eudaptics.com> (raw)
In-Reply-To: <11634257784001-git-send-email-j.sixt@eudaptics.com>

From: Johannes Sixt <johannes.sixt@telecom.at>

If git-write-index is called without --missing-ok, it reports invalid
objects that it finds in the index. But without this patch it dies
right away or may run into an infinite loop.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 cache-tree.c     |    2 ++
 t/t0000-basic.sh |   22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/cache-tree.c b/cache-tree.c
index a803262..9b73c86 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -282,6 +282,8 @@ static int update_one(struct cache_tree 
 				    baselen + sublen + 1,
 				    missing_ok,
 				    dryrun);
+		if (subcnt < 0)
+			return subcnt;
 		i += subcnt - 1;
 		sub->used = 1;
 	}
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 2c9bbb5..6aff0b8 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -209,6 +209,28 @@ test_expect_success \
     'validate object ID for a known tree.' \
     'test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2'
 
+cat >badobjects <<EOF
+100644 blob 1000000000000000000000000000000000000000	dir/file1
+100644 blob 2000000000000000000000000000000000000000	dir/file2
+100644 blob 3000000000000000000000000000000000000000	dir/file3
+100644 blob 4000000000000000000000000000000000000000	dir/file4
+100644 blob 5000000000000000000000000000000000000000	dir/file5
+EOF
+
+rm .git/index
+test_expect_success \
+    'put invalid objects into the index.' \
+    'git-update-index --index-info < badobjects'
+
+test_expect_failure \
+    'writing this tree without --missing-ok.' \
+    'git-write-tree'
+
+test_expect_success \
+    'writing this tree with --missing-ok.' \
+    'git-write-tree --missing-ok'
+
+
 ################################################################
 rm .git/index
 test_expect_success \
-- 
1.4.1.rc1.g47e5

      reply	other threads:[~2006-11-13 13:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-13 13:50 [PATCH] test-lib.sh: A command dying due to a signal is an unexpected failure Johannes Sixt
2006-11-13 13:50 ` Johannes Sixt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11634257782215-git-send-email-j.sixt@eudaptics.com \
    --to=j.sixt@eudaptics.com \
    --cc=git@vger.kernel.org \
    --cc=johannes.sixt@telecom.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).