fuzz: try and generate an interesting mpatch seed from a repo
authorAugie Fackler <augie@google.com>
Sun, 29 Apr 2018 00:29:40 -0400
changeset 38248 99ab72b867b7
parent 38247 06e2fc08f6f0
child 38249 1e9c357d3ddf
fuzz: try and generate an interesting mpatch seed from a repo Differential Revision: https://phab.mercurial-scm.org/D3697
contrib/fuzz/mpatch_corpus.py
--- a/contrib/fuzz/mpatch_corpus.py	Sun Apr 29 00:04:16 2018 -0400
+++ b/contrib/fuzz/mpatch_corpus.py	Sun Apr 29 00:29:40 2018 -0400
@@ -1,9 +1,14 @@
-from __future__ import absolute_import
+from __future__ import absolute_import, print_function
 
 import argparse
 import struct
 import zipfile
 
+from mercurial import (
+    hg,
+    ui as uimod,
+)
+
 ap = argparse.ArgumentParser()
 ap.add_argument("out", metavar="some.zip", type=str, nargs=1)
 args = ap.parse_args()
@@ -59,6 +64,16 @@
         str(corpus('a', [delta([deltafrag(0, 20, 'b')])]))
     )
 
+    try:
+        # Generated from repo data
+        r = hg.repository(uimod.ui(), '../..')
+        fl = r.file('mercurial/manifest.py')
+        rl = getattr(fl, '_revlog', fl)
+        bins = rl._chunks(rl._deltachain(10)[0])
+        zf.writestr('manifest_py_rev_10',
+                    str(corpus(bins[0], bins[1:])))
+    except: # skip this, so no re-raises
+        print('skipping seed file from repo data')
     # Automatically discovered by running the fuzzer
     zf.writestr(
         "mpatch_decode_old_overread", "\x02\x00\x00\x00\x02\x00\x00\x00"