Skip to content

Add fuzzer for datetime module#34

Open
AdamKorcz wants to merge 1 commit intopython:mainfrom
AdamKorcz:add-datetime-fuzzer
Open

Add fuzzer for datetime module#34
AdamKorcz wants to merge 1 commit intopython:mainfrom
AdamKorcz:add-datetime-fuzzer

Conversation

@AdamKorcz
Copy link
Copy Markdown
Contributor

@AdamKorcz AdamKorcz commented Apr 10, 2026

Adds a structured fuzzer for the _datetime C module (Modules/_datetimemodule.c). It has two main branches: parsing and formatting. The parsing branch feeds fuzzed Unicode strings into date.fromisoformat(), time.fromisoformat(), and datetime.fromisoformat() to stress the C-level ISO 8601 parser. The formatting branch constructs valid date, time, and datetime objects with fuzzed field values and then calls strftime() with fuzz-generated format strings, exercising the C formatter's handling of arbitrary directives and edge-case field combinations.

@AdamKorcz AdamKorcz requested a review from a team as a code owner April 10, 2026 19:54
@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-datetime-fuzzer branch from 361a5b8 to 9f80b17 Compare April 11, 2026 21:00
@AdamKorcz AdamKorcz marked this pull request as ready for review April 22, 2026 20:13
@AdamKorcz AdamKorcz force-pushed the add-datetime-fuzzer branch from 9f80b17 to 9195c9d Compare April 22, 2026 21:02
Comment thread datetime.py
hour = fdp.ConsumeIntInRange(0, 23)
minute = fdp.ConsumeIntInRange(0, 59)
second = fdp.ConsumeIntInRange(0, 59)
datetime(year, month, day, hour, minute, second).strftime(fmt)
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.

strftime is quite a thin wrapper around the C lib's strftime, and this is also quite inefficient IMO (the hypothesis PR linked earlier would be far better), as such I don't think this fuzzing is worth it.

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