File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ import sys
2
+
3
+ import atheris
4
+
5
+
6
+ with atheris .instrument_imports ():
7
+ from websockets .exceptions import PayloadTooBig , ProtocolError
8
+ from websockets .frames import Frame
9
+ from websockets .streams import StreamReader
10
+
11
+
12
+ def test_one_input (data ):
13
+ fdp = atheris .FuzzedDataProvider (data )
14
+ mask = fdp .ConsumeBool ()
15
+ max_size_enabled = fdp .ConsumeBool ()
16
+ max_size = fdp .ConsumeInt (4 )
17
+ payload = fdp .ConsumeBytes (atheris .ALL_REMAINING )
18
+
19
+ reader = StreamReader ()
20
+ reader .feed_data (payload )
21
+ reader .feed_eof ()
22
+
23
+ parser = Frame .parse (
24
+ reader .read_exact ,
25
+ mask = mask ,
26
+ max_size = max_size if max_size_enabled else None ,
27
+ )
28
+
29
+ try :
30
+ next (parser )
31
+ except StopIteration :
32
+ pass # response is available in exc.value
33
+ except (
34
+ PayloadTooBig , # frame's payload size exceeds ``max_size``
35
+ ProtocolError , # frame contains incorrect values
36
+ ):
37
+ pass
38
+
39
+
40
+ def main ():
41
+ atheris .Setup (sys .argv , test_one_input )
42
+ atheris .Fuzz ()
43
+
44
+
45
+ if __name__ == "__main__" :
46
+ main ()
You can’t perform that action at this time.
0 commit comments