test-revlog: test a repository that contains a diff against nullrev stable
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Sun, 22 May 2022 23:26:06 +0200
branchstable
changeset 48871 2dd53a33aefa
parent 48870 2fe4efaa59af
child 48872 cc92ad0e8185
test-revlog: test a repository that contains a diff against nullrev We are witnessing a crash in the rust code, so we lets make sure this case is tested.
tests/bundles/test-revlog-diff-relative-to-nullrev.sh
tests/bundles/test-revlog-diff-relative-to-nullrev.tar
tests/test-revlog.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/bundles/test-revlog-diff-relative-to-nullrev.sh	Sun May 22 23:26:06 2022 +0200
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+# Make sure to patch mercurial to create the delta against nullrev
+#          if deltainfo is None:
+#-             deltainfo = self._fullsnapshotinfo(fh, revinfo, target_rev)
+#+             deltainfo = self._builddeltainfo(revinfo, nullrev, fh)
+
+cd "`dirname \"$0\"`"
+export HGRCPATH=
+export HGMODULEPOLICY=py
+
+rm -rf nullrev-diff
+../../hg init nullrev-diff  --config format.revlog-compression=zlib
+cd nullrev-diff
+echo hi > a
+../../../hg commit -Am root-B
+../../../hg debugdeltachain a
+rm -rf .hg/cache/ .hg/wcache/
+cd ..
+
+tar cf test-revlog-diff-relative-to-nullrev.tar nullrev-diff
+
+rm -rf nullrev-diff
Binary file tests/bundles/test-revlog-diff-relative-to-nullrev.tar has changed
--- a/tests/test-revlog.t	Tue May 17 14:36:57 2022 -0400
+++ b/tests/test-revlog.t	Sun May 22 23:26:06 2022 +0200
@@ -32,6 +32,7 @@
 
 Test for CVE-2016-3630
 
+  $ mkdir test2; cd test2
   $ hg init
 
   >>> import codecs
@@ -52,3 +53,37 @@
   >>> rl = revlog.revlog(tvfs, target=(KIND_OTHER, b'test'), radix=b'a')
   >>> rl.revision(1)
   mpatchError(*'patch cannot be decoded'*) (glob)
+
+  $ cd ..
+
+
+Regression test for support for the old repos with strange diff encoding.
+Apparently it used to be possible (maybe it's still possible, but we don't know how)
+to create commits whose diffs are encoded relative to a nullrev.
+This test checks that a repo with that encoding can still be read.
+
+This is what we did to produce the repo in test-revlog-diff-relative-to-nullrev.tar:
+
+- tweak the code in mercurial/revlogutils/deltas.py to produce such "trivial" deltas:
+>          if deltainfo is None:
+> -            deltainfo = self._fullsnapshotinfo(fh, revinfo, target_rev)
+> +            deltainfo = self._builddeltainfo(revinfo, nullrev, fh)
+- hg init
+- echo hi > a
+- hg commit -Am_
+- remove some cache files
+
+  $ tar --force-local -xf "$TESTDIR"/bundles/test-revlog-diff-relative-to-nullrev.tar
+  $ cd nullrev-diff
+  $ hg debugdeltachain a
+      rev  chain# chainlen     prev   delta       size    rawsize  chainsize     ratio   lindist extradist extraratio   readsize largestblk rddensity srchunks
+        0       1        2       -1      p1         15          3         15   5.00000        15         0    0.00000         15         15   1.00000        1
+#if rhg
+  $ hg cat --config rhg.cat=true -r 0 a
+  abort: corrupted revlog
+  [255]
+#else
+  $ hg cat --config rhg.cat=true -r 0 a
+  hi
+#endif
+  $ cd ..