forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_parser.py
More file actions
36 lines (23 loc) · 750 Bytes
/
fuzz_parser.py
File metadata and controls
36 lines (23 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Fuzz target for Parser - Pydantic event validation."""
from __future__ import annotations
import sys
import atheris
with atheris.instrument_imports():
from pydantic import BaseModel, ValidationError
from aws_lambda_powertools.utilities.parser import parse
class SimpleModel(BaseModel):
name: str
value: int
def fuzz_parser(data: bytes) -> None:
"""Fuzz the parser with arbitrary JSON-like data."""
try:
parse(event=data.decode("utf-8", errors="ignore"), model=SimpleModel)
except (ValidationError, ValueError, TypeError, KeyError):
pass
except Exception:
pass
def main() -> None:
atheris.Setup(sys.argv, fuzz_parser)
atheris.Fuzz()
if __name__ == "__main__":
main()