git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG] commit walk machinery is dangerous !
@ 2008-07-14 20:54 Nicolas Pitre
  2008-07-14 21:55 ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Pitre @ 2008-07-14 20:54 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Good!  I have all your attention now.

Yes, I'm kinda fscking upset about my hardware at this moment.  I 
apparently have git packs corrupting themselves from time to time which 
prompted me to make git more robust against some kind of corruptions 
recently.

However this time a corruption turned up and exposed what I think is a 
major flaw in git's error checking.  To demonstrate it, I created the 
following test case.  Turning the error() into a die() on line 772 of 
commit.c makes this test pass but I don't know if this is the 
appropriate fix (e.g. some attempt to parse non existing commits could 
be valid usage, etc.).  Note this is critical only for git versions 
later than commit 8eca0b47ff15.

So here's the test.  The catastrophic consequences that this can have on 
one's repository is left as an exercise to the reader.

diff --git a/t/t6011-rev-list-with-bad-commit.sh b/t/t6011-rev-list-with-bad-commit.sh
new file mode 100755
index 0000000..a5fe190
--- /dev/null
+++ b/t/t6011-rev-list-with-bad-commit.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+test_description='git rev-list should notice bad commits'
+
+. ./test-lib.sh
+
+# Note:
+# - compression level is set to zero to make "corruptions" easier to perform
+# - reflog is disabled to avoid extra references which would twart the test
+
+test_expect_success 'setup' \
+   '
+   git init &&
+   git config core.compression 0 &&
+   git config core.logallrefupdates false &&
+   echo "foo" > foo &&
+   git add foo &&
+   git commit -m "first commit" &&
+   echo "bar" > bar &&
+   git add bar &&
+   git commit -m "second commit" &&
+   echo "baz" > baz &&
+   git add baz &&
+   git commit -m "third commit" &&
+   echo "foo again" >> foo &&
+   git add foo &&
+   git commit -m "fourth commit" &&
+   git repack -a -f -d
+   '
+
+test_expect_success 'verify number of revisions' \
+   '
+   revs=$(git rev-list --all | wc -l) &&
+   test $revs -eq 4 &&
+   first_commit=$(git rev-parse HEAD~3)
+   '
+
+test_expect_success 'corrupt second commit object' \
+   '
+   perl -i.bak -pe "s/second commit/socond commit/" .git/objects/pack/*.pack &&
+   test_must_fail git fsck --all
+   '
+
+test_expect_success 'rev-list should fail' \
+   '
+   test_must_fail git rev-list --all > /dev/null
+   '
+
+test_expect_success 'git repack _MUST_ fail' \
+   '
+   test_must_fail git repack -a -f -d
+   '
+
+test_expect_success 'first commit is still available' \
+   '
+   git log $first_commit
+   '
+
+test_done
+

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-07-15  5:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-14 20:54 [BUG] commit walk machinery is dangerous ! Nicolas Pitre
2008-07-14 21:55 ` Junio C Hamano
2008-07-14 23:08   ` Nicolas Pitre
2008-07-14 23:32     ` Junio C Hamano
2008-07-14 23:39       ` Nicolas Pitre
2008-07-15  1:46         ` [PATCH 1/2] restore legacy behavior for read_sha1_file() Nicolas Pitre
2008-07-15  1:50           ` [PATCH 2/2] test case for previous commit Nicolas Pitre
2008-07-15  5:12           ` [PATCH 1/2] restore legacy behavior for read_sha1_file() Nicolas Pitre
2008-07-15  5:10       ` unpack_entry (was: [BUG] commit walk machinery is dangerous !) Shawn O. Pearce

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).