Mercurial > public > mercurial-scm > hg-stable
diff contrib/fuzz/mpatch_corpus.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 1fb2510cf8c8 |
children | ba84a1ae4ae5 |
line wrap: on
line diff
--- a/contrib/fuzz/mpatch_corpus.py Sat Oct 05 10:29:34 2019 -0400 +++ b/contrib/fuzz/mpatch_corpus.py Sun Oct 06 09:45:02 2019 -0400 @@ -13,6 +13,7 @@ ap.add_argument("out", metavar="some.zip", type=str, nargs=1) args = ap.parse_args() + class deltafrag(object): def __init__(self, start, end, data): self.start = start @@ -20,8 +21,11 @@ self.data = data def __str__(self): - return struct.pack( - ">lll", self.start, self.end, len(self.data)) + self.data + return ( + struct.pack(">lll", self.start, self.end, len(self.data)) + + self.data + ) + class delta(object): def __init__(self, frags): @@ -30,8 +34,8 @@ def __str__(self): return ''.join(str(f) for f in self.frags) + class corpus(object): - def __init__(self, base, deltas): self.base = base self.deltas = deltas @@ -49,19 +53,19 @@ ) return "".join(parts) + with zipfile.ZipFile(args.out[0], "w", zipfile.ZIP_STORED) as zf: # Manually constructed entries zf.writestr( - "one_delta_applies", - str(corpus('a', [delta([deltafrag(0, 1, 'b')])])) + "one_delta_applies", str(corpus('a', [delta([deltafrag(0, 1, 'b')])])) ) zf.writestr( "one_delta_starts_late", - str(corpus('a', [delta([deltafrag(3, 1, 'b')])])) + str(corpus('a', [delta([deltafrag(3, 1, 'b')])])), ) zf.writestr( "one_delta_ends_late", - str(corpus('a', [delta([deltafrag(0, 20, 'b')])])) + str(corpus('a', [delta([deltafrag(0, 20, 'b')])])), ) try: @@ -70,9 +74,8 @@ 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 + 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( @@ -81,7 +84,8 @@ # https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8876 zf.writestr( "mpatch_ossfuzz_getbe32_ubsan", - "\x02\x00\x00\x00\x0c \xff\xff\xff\xff ") + "\x02\x00\x00\x00\x0c \xff\xff\xff\xff ", + ) zf.writestr( "mpatch_apply_over_memcpy", '\x13\x01\x00\x05\xd0\x00\x00\x00\x00\x00\x00\x00\x00\n \x00\x00\x00' @@ -342,4 +346,5 @@ '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00se\x00\x00' '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - '\x00\x00\x00\x00') + '\x00\x00\x00\x00', + )