File tree Expand file tree Collapse file tree 3 files changed +38
-9
lines changed Expand file tree Collapse file tree 3 files changed +38
-9
lines changed Original file line number Diff line number Diff line change
1
+ name : Fuzz parser
2
+
3
+ # Run this workflow on changes to the external scanner
4
+ on :
5
+ workflow_dispatch :
6
+ # push:
7
+ # paths:
8
+ # - src/scanner.c
9
+ # - src/stack.h
10
+ # pull_request:
11
+ # paths:
12
+ # - src/scanner.c
13
+ # - src/stack.h
14
+
15
+ jobs :
16
+ test :
17
+ name : Parser fuzzing
18
+ runs-on : ubuntu-latest
19
+ steps :
20
+ - uses : actions/checkout@v3
21
+ - uses : eed3si9n/tree-sitter-fuzz-action@v1
22
+ with :
23
+ language : scala
24
+ external-scanner : src/scanner.c
25
+ time : 60
Original file line number Diff line number Diff line change 10
10
#define LOG (...)
11
11
#endif
12
12
13
- #define STACK_SIZE 1024
13
+ // Total payload size is 1024 bytes max
14
+ #define STACK_SIZE 100
14
15
15
16
typedef struct ScannerStack {
16
- unsigned int stack [STACK_SIZE ];
17
+ int stack [STACK_SIZE ];
17
18
int top ;
18
19
int last_indentation_size ;
19
20
int last_newline_count ;
@@ -63,7 +64,10 @@ void printStack(ScannerStack *stack, char *msg) {
63
64
}
64
65
65
66
unsigned serialiseStack (ScannerStack * stack , char * buf ) {
66
- unsigned elements = isEmptyStack (stack ) ? 0 : stack -> top ;
67
+ int elements = isEmptyStack (stack ) ? 0 : stack -> top ;
68
+ if (elements < 0 ) {
69
+ elements = 0 ;
70
+ }
67
71
unsigned result_length = (elements + 3 ) * sizeof (int );
68
72
int * placement = (int * )buf ;
69
73
memcpy (placement , stack -> stack , elements * sizeof (int ));
Original file line number Diff line number Diff line change @@ -26,19 +26,19 @@ int main() {
26
26
assert (peekStack (stack ) == -1 );
27
27
assert (isEmptyStack (stack ));
28
28
29
- char * buf = malloc (2048 );
29
+ char * buf = malloc (1024 );
30
30
31
- for (int i = 0 ; i < 250 ; i ++ ) {
31
+ for (int i = 0 ; i < 100 ; i ++ ) {
32
32
pushStack (stack , i );
33
33
}
34
34
35
- assert (serialiseStack (stack , buf ) == sizeof (int ) * 253 );
35
+ assert (serialiseStack (stack , buf ) == sizeof (int ) * 103 );
36
36
37
37
ScannerStack * newStack = createStack ();
38
38
39
- deserialiseStack (newStack , buf , sizeof (int ) * 253 );
40
- assert (newStack -> top == 250 );
41
- assert (popStack (newStack ) == 249 );
39
+ deserialiseStack (newStack , buf , sizeof (int ) * 103 );
40
+ assert (newStack -> top == 100 );
41
+ assert (popStack (newStack ) == 99 );
42
42
43
43
resetStack (newStack );
44
44
You can’t perform that action at this time.
0 commit comments