Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: fuzzer-binascii fuzzer-html fuzzer-email fuzzer-httpclient fuzzer-json fuzzer-difflib fuzzer-csv fuzzer-decode fuzzer-ast fuzzer-tarfile fuzzer-tarfile-hypothesis fuzzer-zipfile fuzzer-zipfile-hypothesis fuzzer-re fuzzer-configparser fuzzer-tomllib fuzzer-plistlib fuzzer-xml fuzzer-zoneinfo
all: fuzzer-binascii fuzzer-html fuzzer-email fuzzer-httpclient fuzzer-json fuzzer-difflib fuzzer-csv fuzzer-decode fuzzer-ast fuzzer-tarfile fuzzer-tarfile-hypothesis fuzzer-zipfile fuzzer-zipfile-hypothesis fuzzer-re fuzzer-configparser fuzzer-tomllib fuzzer-plistlib fuzzer-xml fuzzer-zoneinfo fuzzer-datetime

PYTHON_CONFIG_PATH=$(CPYTHON_INSTALL_PATH)/bin/python3-config
CXXFLAGS += $(shell $(PYTHON_CONFIG_PATH) --cflags)
Expand Down Expand Up @@ -42,3 +42,6 @@ fuzzer-xml:
clang++ $(CXXFLAGS) $(LIB_FUZZING_ENGINE) -std=c++17 fuzzer.cpp -DPYTHON_HARNESS_PATH="\"xml.py\"" -ldl $(LDFLAGS) -o fuzzer-xml
fuzzer-zoneinfo:
clang++ $(CXXFLAGS) $(LIB_FUZZING_ENGINE) -std=c++17 fuzzer.cpp -DPYTHON_HARNESS_PATH="\"zoneinfo.py\"" -ldl $(LDFLAGS) -o fuzzer-zoneinfo

fuzzer-datetime:
clang++ $(CXXFLAGS) $(LIB_FUZZING_ENGINE) -std=c++17 fuzzer.cpp -DPYTHON_HARNESS_PATH="\"datetime.py\"" -ldl $(LDFLAGS) -o fuzzer-datetime
Binary file added corp-datetime/date_0
Binary file not shown.
Binary file added corp-datetime/date_1
Binary file not shown.
Binary file added corp-datetime/date_2
Binary file not shown.
Binary file added corp-datetime/date_3
Binary file not shown.
1 change: 1 addition & 0 deletions corp-datetime/datetime_0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-01-15T10:30
1 change: 1 addition & 0 deletions corp-datetime/datetime_1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-01-15 10:30:00
1 change: 1 addition & 0 deletions corp-datetime/datetime_2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-01-15T10:30:00.123456
1 change: 1 addition & 0 deletions corp-datetime/datetime_3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-01-15T10:30:00+01:00
1 change: 1 addition & 0 deletions corp-datetime/datetime_4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-01-15T10:30:00.123456-05:30
1 change: 1 addition & 0 deletions corp-datetime/datetime_5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0001-01-01T00:00:00
1 change: 1 addition & 0 deletions corp-datetime/datetime_6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9999-12-31T23:59:59.999999+00:00
1 change: 1 addition & 0 deletions corp-datetime/datetime_7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-06-01T12:00:00.000001+02:00
1 change: 1 addition & 0 deletions corp-datetime/time_0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10:30
1 change: 1 addition & 0 deletions corp-datetime/time_1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10:30:00
1 change: 1 addition & 0 deletions corp-datetime/time_2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10:30:00.123456
1 change: 1 addition & 0 deletions corp-datetime/time_3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10:30:00,5
1 change: 1 addition & 0 deletions corp-datetime/time_4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
00:00
1 change: 1 addition & 0 deletions corp-datetime/time_5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
23:59:59.999999
1 change: 1 addition & 0 deletions corp-datetime/time_6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10:30+01:00
1 change: 1 addition & 0 deletions corp-datetime/time_7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10:30:00-05:30
1 change: 1 addition & 0 deletions corp-datetime/time_8
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10:30:00.123456+01:00:30
45 changes: 45 additions & 0 deletions datetime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Fuzz the C ISO-8601 fast parsers and date/time arithmetic.

date, time and datetime fromisoformat() are implemented in C
(Modules/_datetimemodule.c) and parse attacker-controlled strings.
Two properties are exercised: isoformat() must round-trip through
fromisoformat (documented inverse -- a mismatch is a logic bug and
raises AssertionError), and fuzzed timedelta shifts drive the C
normalisation and overflow-checking paths. Invalid ISO strings are
expected and raise ValueError/TypeError; time objects reject +/- with
TypeError.
"""
from datetime import date, datetime, time, timedelta


def FuzzerRunOne(FuzzerInput):
if len(FuzzerInput) < 3:
return
op = FuzzerInput[0]
amount = FuzzerInput[1]
data = FuzzerInput[2:].decode("utf-8", "replace")
if op % 3 == 0:
parse = date.fromisoformat
elif op % 3 == 1:
parse = time.fromisoformat
else:
parse = datetime.fromisoformat
try:
parsed = parse(data)
except (ValueError, TypeError):
return

# Round-trip property: fromisoformat is the documented inverse of
# isoformat(), for all three types.
reparsed = type(parsed).fromisoformat(parsed.isoformat())
if reparsed != parsed:
raise AssertionError(
"isoformat round-trip mismatch: %r -> %r" % (parsed, parsed.isoformat())
)

delta = timedelta(amount % 30, amount % 60, amount % 1000000)
try:
parsed + delta
parsed - delta
except (TypeError, OverflowError):
pass
1 change: 1 addition & 0 deletions fuzz_targets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ast ast.py
binascii binascii.py
configparser configparser.py
csv csv.py
datetime datetime.py
decode decode.py
difflib difflib.py
email email.py
Expand Down
33 changes: 33 additions & 0 deletions fuzzer-datetime.dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ISO-8601 tokens for date/time/datetime.fromisoformat
"T"
"Z"
"z"
"+01:00"
"+01:00:30"
"-05:30"
"+0000"
"+01"
"2024-01-15"
"2024-01-15T10:30"
"2024-01-15 10:30:00"
"10:30"
"10:30:00"
"10:30:00.123456"
"10:30:00,5"
".123456"
",123"
"24:00"
"00:00"
"W"
"-W"
"2024-W03-1"
"2024-W03"
"2024-021"
"0001-01-01"
"9999-12-31"
"23:59:59.999999"
"+23:59"
"-23:59"
"hh"
"mm"
"ss"