Skip to content

Commit 148cf5d

Browse files
Rewrite decode.py to always pick a valid codec
1 parent ab60539 commit 148cf5d

File tree

2 files changed

+16
-329
lines changed

2 files changed

+16
-329
lines changed

decode.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1+
import encodings
2+
import pkgutil
3+
4+
ALL_CODECS = sorted(
5+
name
6+
for _, name, _ in pkgutil.iter_modules(encodings.__path__)
7+
if not name.startswith("_") and name != "aliases"
8+
)
9+
10+
111
def FuzzerRunOne(FuzzerInput):
2-
half = int(len(FuzzerInput) / 2)
3-
A = FuzzerInput[:half]
4-
B = FuzzerInput[half:].decode("utf-8", "replace").strip()
12+
if len(FuzzerInput) < 2:
13+
return
14+
codec = ALL_CODECS[FuzzerInput[0] % len(ALL_CODECS)]
15+
data = FuzzerInput[1:]
516
try:
6-
A.decode(B)
17+
data.decode(codec)
718
except SystemError:
819
raise
9-
except:
20+
except Exception:
1021
pass

fuzzer-decode.dict

Lines changed: 0 additions & 324 deletions
This file was deleted.

0 commit comments

Comments
 (0)