Debian Codegraph @

fuzzing/fuzz_http11_response_parser.py

raw
1 import sys
2
3 import atheris
4
5
6 with atheris.instrument_imports():
7 from websockets.exceptions import SecurityError
8 from websockets.http11 import Response
9 from websockets.streams import StreamReader
10
11
12 def test_one_input(data):
13 reader = StreamReader()
14 reader.feed_data(data)
15 reader.feed_eof()
16
17 parser = Response.parse(
18 reader.read_line,
19 reader.read_exact,
20 reader.read_to_eof,
21 )
22 try:
23 next(parser)
24 except StopIteration as exc:
25 assert isinstance(exc.value, Response)
26 return # input accepted
27 except (
28 EOFError, # connection is closed without a full HTTP response
29 SecurityError, # response exceeds a security limit
30 LookupError, # response isn't well formatted
31 ValueError, # response isn't well formatted
32 ):
33 return # input rejected with a documented exception
34
35 raise RuntimeError("parsing didn't complete")
36
37
38 def main():
39 atheris.Setup(sys.argv, test_one_input)
40 atheris.Fuzz()
41
42
43 if __name__ == "__main__":
44 main()