D7601: fuzz: fix test-fuzz-targets.t to run with python3
spectral created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D7601 AFFECTED FILES contrib/fuzz/dirstate_corpus.py contrib/fuzz/mpatch_corpus.py contrib/fuzz/revlog_corpus.py CHANGE DETAILS diff --git a/contrib/fuzz/revlog_corpus.py b/contrib/fuzz/revlog_corpus.py --- a/contrib/fuzz/revlog_corpus.py +++ b/contrib/fuzz/revlog_corpus.py @@ -18,8 +18,8 @@ with zipfile.ZipFile(args.out[0], "w", zipfile.ZIP_STORED) as zf: if os.path.exists(changelog): -with open(changelog) as f: +with open(changelog, 'rb') as f: zf.writestr("00changelog.i", f.read()) if os.path.exists(contributing): -with open(contributing) as f: +with open(contributing, 'rb') as f: zf.writestr("contributing.i", f.read()) diff --git a/contrib/fuzz/mpatch_corpus.py b/contrib/fuzz/mpatch_corpus.py --- a/contrib/fuzz/mpatch_corpus.py +++ b/contrib/fuzz/mpatch_corpus.py @@ -20,7 +20,11 @@ self.end = end self.data = data -def __str__(self): +def __repr__(self): +# py2 calls __repr__ when you do `bytes(foo)` +return self.__bytes__() + +def __bytes__(self): return ( struct.pack(">lll", self.start, self.end, len(self.data)) + self.data @@ -31,8 +35,12 @@ def __init__(self, frags): self.frags = frags -def __str__(self): -return ''.join(str(f) for f in self.frags) +def __repr__(self): +# py2 calls __repr__ when you do `bytes(foo)` +return self.__bytes__() + +def __bytes__(self): +return b''.join(bytes(f) for f in self.frags) class corpus(object): @@ -40,8 +48,12 @@ self.base = base self.deltas = deltas -def __str__(self): -deltas = [str(d) for d in self.deltas] +def __repr__(self): +# py2 calls __repr__ when you do `bytes(foo)` +return self.__bytes__() + +def __bytes__(self): +deltas = [bytes(d) for d in self.deltas] parts = ( [ struct.pack(">B", len(deltas) + 1), @@ -51,300 +63,301 @@ + [self.base] + deltas ) -return "".join(parts) +return b''.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", +bytes(corpus(b'a', [delta([deltafrag(0, 1, b'b')])])) ) zf.writestr( "one_delta_starts_late", -str(corpus('a', [delta([deltafrag(3, 1, 'b')])])), +bytes(corpus(b'a', [delta([deltafrag(3, 1, b'b')])])) ) zf.writestr( "one_delta_ends_late", -str(corpus('a', [delta([deltafrag(0, 20, 'b')])])), +bytes(corpus(b'a', [delta([deltafrag(0, 20, b'b')])])) ) try: # Generated from repo data -r = hg.repository(uimod.ui(), '../..') -fl = r.file('mercurial/manifest.py') +r = hg.repository(uimod.ui(), b'../..') +fl = r.file(b'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:]))) +zf.writestr('manifest_py_rev_10', bytes(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" +"mpatch_decode_old_overread", b"\x02\x00\x00\x00\x02\x00\x00\x00" ) # 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", +b"\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' -'\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\xff\xff\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\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\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' -'\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\x00\x00\x00\x00' -'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
D7601: fuzz: fix test-fuzz-targets.t to run with python3
Closed by commit rHGba84a1ae4ae5: fuzz: fix test-fuzz-targets.t to run with python3 (authored by spectral). This revision was automatically updated to reflect the committed changes. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7601?vs=18595&id=18600 CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7601/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7601 AFFECTED FILES contrib/fuzz/dirstate_corpus.py contrib/fuzz/mpatch_corpus.py contrib/fuzz/revlog_corpus.py CHANGE DETAILS diff --git a/contrib/fuzz/revlog_corpus.py b/contrib/fuzz/revlog_corpus.py --- a/contrib/fuzz/revlog_corpus.py +++ b/contrib/fuzz/revlog_corpus.py @@ -18,8 +18,8 @@ with zipfile.ZipFile(args.out[0], "w", zipfile.ZIP_STORED) as zf: if os.path.exists(changelog): -with open(changelog) as f: +with open(changelog, 'rb') as f: zf.writestr("00changelog.i", f.read()) if os.path.exists(contributing): -with open(contributing) as f: +with open(contributing, 'rb') as f: zf.writestr("contributing.i", f.read()) diff --git a/contrib/fuzz/mpatch_corpus.py b/contrib/fuzz/mpatch_corpus.py --- a/contrib/fuzz/mpatch_corpus.py +++ b/contrib/fuzz/mpatch_corpus.py @@ -20,7 +20,11 @@ self.end = end self.data = data -def __str__(self): +def __repr__(self): +# py2 calls __repr__ when you do `bytes(foo)` +return self.__bytes__() + +def __bytes__(self): return ( struct.pack(">lll", self.start, self.end, len(self.data)) + self.data @@ -31,8 +35,12 @@ def __init__(self, frags): self.frags = frags -def __str__(self): -return ''.join(str(f) for f in self.frags) +def __repr__(self): +# py2 calls __repr__ when you do `bytes(foo)` +return self.__bytes__() + +def __bytes__(self): +return b''.join(bytes(f) for f in self.frags) class corpus(object): @@ -40,8 +48,12 @@ self.base = base self.deltas = deltas -def __str__(self): -deltas = [str(d) for d in self.deltas] +def __repr__(self): +# py2 calls __repr__ when you do `bytes(foo)` +return self.__bytes__() + +def __bytes__(self): +deltas = [bytes(d) for d in self.deltas] parts = ( [ struct.pack(">B", len(deltas) + 1), @@ -51,300 +63,301 @@ + [self.base] + deltas ) -return "".join(parts) +return b''.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", +bytes(corpus(b'a', [delta([deltafrag(0, 1, b'b')])])) ) zf.writestr( "one_delta_starts_late", -str(corpus('a', [delta([deltafrag(3, 1, 'b')])])), +bytes(corpus(b'a', [delta([deltafrag(3, 1, b'b')])])) ) zf.writestr( "one_delta_ends_late", -str(corpus('a', [delta([deltafrag(0, 20, 'b')])])), +bytes(corpus(b'a', [delta([deltafrag(0, 20, b'b')])])) ) try: # Generated from repo data -r = hg.repository(uimod.ui(), '../..') -fl = r.file('mercurial/manifest.py') +r = hg.repository(uimod.ui(), b'../..') +fl = r.file(b'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:]))) +zf.writestr('manifest_py_rev_10', bytes(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" +"mpatch_decode_old_overread", b"\x02\x00\x00\x00\x02\x00\x00\x00" ) # 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", +b"\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' -'\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\xff\xff\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\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\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' -
D7601: fuzz: fix test-fuzz-targets.t to run with python3
mharbison72 added inline comments. INLINE COMMENTS > mpatch_corpus.py:53 > +# py2 calls __repr__ when you do `bytes(foo)` > +return self.__bytes__() > + Doesn't `__repr__` have to return `str` on py3? It looks like there are few other instances of this. REPOSITORY rHG Mercurial CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7601/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7601 To: spectral, #hg-reviewers, pulkit Cc: mharbison72, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D7601: fuzz: fix test-fuzz-targets.t to run with python3
pulkit added inline comments. INLINE COMMENTS > mharbison72 wrote in mpatch_corpus.py:53 > Doesn't `__repr__` have to return `str` on py3? It looks like there are few > other instances of this. ha, yep. @spectral can you send a follow-up for this? REPOSITORY rHG Mercurial CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7601/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7601 To: spectral, #hg-reviewers, pulkit Cc: mharbison72, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel