From 73371ad32449921d75bce54b6657b6840e1bb387 Mon Sep 17 00:00:00 2001 From: DavidKorczynski Date: Thu, 4 Aug 2022 13:34:09 +0100 Subject: [PATCH] iniconfig: fix fuzzer (#8146) The file operations had issues with file not found. This will trigger the same parsing routines but without file operations. Fixes: https://github.com/pytest-dev/iniconfig/issues/41 --- projects/iniconfig/fuzz_parse.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/projects/iniconfig/fuzz_parse.py b/projects/iniconfig/fuzz_parse.py index c6dd36eaa..141fdf55d 100644 --- a/projects/iniconfig/fuzz_parse.py +++ b/projects/iniconfig/fuzz_parse.py @@ -21,13 +21,12 @@ import iniconfig def TestOneInput(data): """Simple fuzzer that targets parse routine""" - with open("example.ini", "wb") as f: - f.write(data) + fdp = atheris.FuzzedDataProvider(data) try: - ini = iniconfig.IniConfig("example.ini") - except (iniconfig.ParseError, UnicodeDecodeError) as e: + ini = iniconfig.IniConfig(None, fdp.ConsumeUnicodeNoSurrogates(sys.maxsize)) + except iniconfig.ParseError: pass - os.remove("example.ini") + def main(): atheris.instrument_all()