raise RevlogError when parser can't parse the revlog index
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Mon, 06 Apr 2009 19:48:11 +0200
changeset 8016 baaa832fd253
parent 7929 47b0a881638f
child 8017 685ce2f7ee35
child 8035 cb77c0fbec39
raise RevlogError when parser can't parse the revlog index Initial patch and test thanks to Nicolas Dumazet.
mercurial/revlog.py
tests/test-verify
tests/test-verify.out
--- a/mercurial/revlog.py	Tue Mar 31 07:56:28 2009 +0200
+++ b/mercurial/revlog.py	Mon Apr 06 19:48:11 2009 +0200
@@ -450,7 +450,10 @@
         if self.version == REVLOGV0:
             self._io = revlogoldio()
         if i:
-            d = self._io.parseindex(f, self._inline)
+            try:
+                d = self._io.parseindex(f, self._inline)
+            except (ValueError, IndexError), e:
+                raise RevlogError(_("index %s is corrupted") % (self.indexfile))
             self.index, self.nodemap, self._chunkcache = d
 
         # add the magic null revision at -1 (if it hasn't been done already)
--- a/tests/test-verify	Tue Mar 31 07:56:28 2009 +0200
+++ b/tests/test-verify	Mon Apr 06 19:48:11 2009 +0200
@@ -1,7 +1,8 @@
 #!/bin/sh
 
 echo % prepare repo
-hg init
+hg init a
+cd a
 echo "some text" > FOO.txt
 echo "another text" > bar.txt
 echo "more text" > QUICK.txt
@@ -23,4 +24,22 @@
 echo % verify
 hg verify
 
+cd ..
+
+echo % test revlog corruption
+hg init b
+cd b
+
+touch a
+hg add a
+hg ci -m a
+
+echo 'corrupted' > b
+head -c 20 .hg/store/data/a.i > start
+cat start b > .hg/store/data/a.i
+
+echo
+echo % verify
+hg verify
+
 exit 0
--- a/tests/test-verify.out	Tue Mar 31 07:56:28 2009 +0200
+++ b/tests/test-verify.out	Mon Apr 06 19:48:11 2009 +0200
@@ -29,3 +29,16 @@
 3 files, 1 changesets, 0 total revisions
 9 integrity errors encountered!
 (first damaged changeset appears to be 0)
+% test revlog corruption
+
+% verify
+checking changesets
+checking manifests
+crosschecking files in changesets and manifests
+checking files
+ a@0: broken revlog! (index data/a.i is corrupted)
+warning: orphan revlog 'data/a.i'
+1 files, 1 changesets, 0 total revisions
+1 warnings encountered!
+1 integrity errors encountered!
+(first damaged changeset appears to be 0)