|
| 1 | +"""Fuzz target for Event Source Data Classes - SQS, SNS, API Gateway, Kinesis parsing.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import json |
| 6 | +import sys |
| 7 | + |
| 8 | +import atheris |
| 9 | + |
| 10 | +with atheris.instrument_imports(): |
| 11 | + from aws_lambda_powertools.utilities.data_classes import ( |
| 12 | + APIGatewayProxyEvent, |
| 13 | + KinesisStreamEvent, |
| 14 | + SNSEvent, |
| 15 | + SQSEvent, |
| 16 | + ) |
| 17 | + |
| 18 | + |
| 19 | +def fuzz_sqs_event(data: bytes) -> None: |
| 20 | + """Fuzz SQS event parsing.""" |
| 21 | + try: |
| 22 | + event_dict = json.loads(data.decode("utf-8", errors="ignore")) |
| 23 | + SQSEvent(event_dict) |
| 24 | + except (json.JSONDecodeError, KeyError, TypeError, ValueError): |
| 25 | + pass |
| 26 | + except Exception: |
| 27 | + pass |
| 28 | + |
| 29 | + |
| 30 | +def fuzz_sns_event(data: bytes) -> None: |
| 31 | + """Fuzz SNS event parsing.""" |
| 32 | + try: |
| 33 | + event_dict = json.loads(data.decode("utf-8", errors="ignore")) |
| 34 | + SNSEvent(event_dict) |
| 35 | + except (json.JSONDecodeError, KeyError, TypeError, ValueError): |
| 36 | + pass |
| 37 | + except Exception: |
| 38 | + pass |
| 39 | + |
| 40 | + |
| 41 | +def fuzz_api_gateway_event(data: bytes) -> None: |
| 42 | + """Fuzz API Gateway event parsing.""" |
| 43 | + try: |
| 44 | + event_dict = json.loads(data.decode("utf-8", errors="ignore")) |
| 45 | + APIGatewayProxyEvent(event_dict) |
| 46 | + except (json.JSONDecodeError, KeyError, TypeError, ValueError): |
| 47 | + pass |
| 48 | + except Exception: |
| 49 | + pass |
| 50 | + |
| 51 | + |
| 52 | +def fuzz_kinesis_event(data: bytes) -> None: |
| 53 | + """Fuzz Kinesis event parsing.""" |
| 54 | + try: |
| 55 | + event_dict = json.loads(data.decode("utf-8", errors="ignore")) |
| 56 | + KinesisStreamEvent(event_dict) |
| 57 | + except (json.JSONDecodeError, KeyError, TypeError, ValueError): |
| 58 | + pass |
| 59 | + except Exception: |
| 60 | + pass |
| 61 | + |
| 62 | + |
| 63 | +def fuzz_all_events(data: bytes) -> None: |
| 64 | + """Fuzz all event sources.""" |
| 65 | + fuzz_sqs_event(data) |
| 66 | + fuzz_sns_event(data) |
| 67 | + fuzz_api_gateway_event(data) |
| 68 | + fuzz_kinesis_event(data) |
| 69 | + |
| 70 | + |
| 71 | +def main() -> None: |
| 72 | + atheris.Setup(sys.argv, fuzz_all_events) |
| 73 | + atheris.Fuzz() |
| 74 | + |
| 75 | + |
| 76 | +if __name__ == "__main__": |
| 77 | + main() |
0 commit comments