Skip to content

Add fuzzer for json_encode module#33

Open
AdamKorcz wants to merge 2 commits into
python:mainfrom
AdamKorcz:add-json-encode-fuzzer
Open

Add fuzzer for json_encode module#33
AdamKorcz wants to merge 2 commits into
python:mainfrom
AdamKorcz:add-json-encode-fuzzer

Conversation

@AdamKorcz

@AdamKorcz AdamKorcz commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Adds a structured fuzzer for the _json C module's encoding paths (Modules/_json.c). The fuzzer constructs Python containers - int lists, string-keyed dicts, tuples, floats, and bare ints - from fuzzed input, then encodes them through json.dumps() under varied configurations. Separate branches exercise the default encoder, ensure_ascii in both modes, sort_keys, indented output with fuzzed indent levels, and a fully custom JSONEncoder with randomized separators and allow_nan settings. The goal is to cover the C-accelerated encoder's handling of diverse object graphs and option combinations..

@AdamKorcz AdamKorcz requested a review from a team as a code owner April 10, 2026 19:53
@AdamKorcz AdamKorcz marked this pull request as draft April 10, 2026 21:27
@AdamKorcz AdamKorcz marked this pull request as draft April 10, 2026 21:27
@AdamKorcz AdamKorcz marked this pull request as draft April 10, 2026 21:27
@AdamKorcz AdamKorcz force-pushed the add-json-encode-fuzzer branch from 0fe6cb6 to d43769c Compare April 11, 2026 21:00
@AdamKorcz AdamKorcz marked this pull request as ready for review April 22, 2026 20:12
@AdamKorcz AdamKorcz force-pushed the add-json-encode-fuzzer branch from d43769c to 274addc Compare May 26, 2026 10:38
@AdamKorcz AdamKorcz force-pushed the add-json-encode-fuzzer branch from 0c0c94d to c96ce26 Compare June 2, 2026 18:50
Comment thread json_encode.py
enc.encode(obj)
except (ValueError, TypeError, RecursionError, OverflowError):
pass
except Exception:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't ignore SystemErrors, they generally always mean something has gone wrong internally.

Comment thread json_encode.py
@@ -0,0 +1,86 @@
from fuzzeddataprovider import FuzzedDataProvider
import json

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants