Skip to content

Commit 8225d0b

Browse files
committed
add var header fuzzing
1 parent e7408db commit 8225d0b

6 files changed

Lines changed: 34 additions & 4 deletions

File tree

.github/workflows/fuzz.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
test: [ "TFChannelRange_read", "TFCompressionBlock_read", "TFHeader_read" ]
17+
test: [ "TFChannelRange_read", "TFCompressionBlock_read", "TFHeader_read", "TFVarHeader_read" ]
1818

1919
steps:
2020
- uses: actions/checkout@v4

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ if (ENABLE_FUZZING)
2323
add_executable(fuzz_TFHeader_read fuzz/TFHeader_read.c)
2424
target_link_libraries(fuzz_TFHeader_read "-fsanitize=fuzzer")
2525
target_compile_options(fuzz_TFHeader_read PRIVATE "-fsanitize=fuzzer")
26+
27+
add_executable(fuzz_TFVarHeader_read fuzz/TFVarHeader_read.c)
28+
target_link_libraries(fuzz_TFVarHeader_read "-fsanitize=fuzzer")
29+
target_compile_options(fuzz_TFVarHeader_read PRIVATE "-fsanitize=fuzzer")
2630
endif ()

fuzz/TFChannelRange_read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "../tinyfseq.h"
55

66
int LLVMFuzzerTestOneInput(const uint8_t *data, const size_t size) {
7-
TFChannelRange range;
7+
TFChannelRange range = {0};
88
TFChannelRange_read(data, size, &range, NULL);
99
return 0;
1010
}

fuzz/TFCompressionBlock_read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "../tinyfseq.h"
55

66
int LLVMFuzzerTestOneInput(const uint8_t *data, const size_t size) {
7-
TFCompressionBlock block;
7+
TFCompressionBlock block = {0};
88
TFCompressionBlock_read(data, size, &block, NULL);
99
return 0;
1010
}

fuzz/TFHeader_read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "../tinyfseq.h"
55

66
int LLVMFuzzerTestOneInput(const uint8_t *data, const size_t size) {
7-
TFHeader header;
7+
TFHeader header = {0};
88
TFHeader_read(data, size, &header, NULL);
99
return 0;
1010
}

fuzz/TFVarHeader_read.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <assert.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
#define TINYFSEQ_IMPLEMENTATION
6+
#include "../tinyfseq.h"
7+
8+
int LLVMFuzzerTestOneInput(const uint8_t *data, const size_t size) {
9+
// attempt to read an initial header value
10+
TFVarHeader header = {0};
11+
if (TFVarHeader_read(data, size, &header, NULL, 0, NULL) != TF_OK) return 0;
12+
13+
if (header.size == 0) return 0;
14+
15+
// allocate a buffer for the variable data
16+
// manually subtract 4 to account for the header base size
17+
const uint16_t vdsize = header.size - 4;
18+
uint8_t *vd = malloc(vdsize);
19+
assert(vd != NULL);
20+
21+
TFVarHeader_read(data, size, &header, vd, vdsize, NULL);
22+
23+
free(vd);
24+
25+
return 0;
26+
}

0 commit comments

Comments
 (0)