changeset 38260:99ab72b867b7

fuzz: try and generate an interesting mpatch seed from a repo Differential Revision: https://phab.mercurial-scm.org/D3697
author Augie Fackler <augie@google.com>
date Sun, 29 Apr 2018 00:29:40 -0400
parents 06e2fc08f6f0
children 1e9c357d3ddf
files contrib/fuzz/mpatch_corpus.py
diffstat 1 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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"