Skip to content

Commit 411479d

Browse files
committed
add build fuzzing workflows
1 parent aeb161f commit 411479d

11 files changed

Lines changed: 219 additions & 78 deletions

File tree

.github/workflows/cmake.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: CMake
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches: [ "main" ]
7+
8+
env:
9+
BUILD_TYPE: RelWithDebInfo
10+
11+
jobs:
12+
Ubuntu:
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
compiler: [ "clang", "gcc" ]
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
submodules: true
23+
24+
- name: Configure CMake
25+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=${{matrix.compiler}}
26+
27+
- name: Build
28+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
29+
30+
- name: CTest
31+
working-directory: ${{github.workspace}}/build
32+
run: ctest -C ${{env.BUILD_TYPE}}
33+
34+
Windows:
35+
runs-on: windows-latest
36+
37+
defaults:
38+
run:
39+
shell: msys2 {0}
40+
41+
steps:
42+
- uses: msys2/setup-msys2@v2
43+
with:
44+
msystem: mingw64
45+
pacboy: >-
46+
gcc:p
47+
cmake:p
48+
ninja:p
49+
50+
- uses: actions/checkout@v4
51+
with:
52+
submodules: true
53+
54+
- name: Configure CMake
55+
run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -G Ninja
56+
57+
- name: Build
58+
run: cmake --build build --config ${{env.BUILD_TYPE}}
59+
60+
- name: CTest
61+
working-directory: ${{github.workspace}}\build
62+
run: ctest -C ${{env.BUILD_TYPE}}
63+
64+
macOS:
65+
runs-on: macos-latest
66+
67+
steps:
68+
- uses: actions/checkout@v4
69+
with:
70+
submodules: true
71+
72+
- name: Configure CMake
73+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
74+
75+
- name: Build
76+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
77+
78+
- name: CTest
79+
working-directory: ${{github.workspace}}/build
80+
run: ctest -C ${{env.BUILD_TYPE}}

.github/workflows/fuzz.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Fuzz
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches: [ "main" ]
7+
8+
env:
9+
BUILD_TYPE: Debug
10+
11+
jobs:
12+
Fuzz:
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
test: [ "TFChannelRange_read", "TFCompressionBlock_read", "TFHeader_read" ]
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Configure CMake
23+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=clang -DENABLE_FUZZING=TRUE
24+
25+
- name: Build
26+
run: cmake --build ${{github.workspace}}/build --target fuzz_${{matrix.test}} --config ${{env.BUILD_TYPE}}
27+
28+
- name: Fuzz
29+
working-directory: ${{github.workspace}}/build
30+
run: |
31+
mkdir -p corpus
32+
./fuzz_${{matrix.test}} -max_total_time=30 -print_final_stats=1 corpus
33+
34+
- uses: actions/upload-artifact@v4
35+
with:
36+
name: ${{matrix.test}}_corpus
37+
path: ${{github.workspace}}/build/corpus

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
# CLion
22
.idea/
3+
4+
# CMake
5+
cmake-build-debug/
6+
cmake-build-release/

CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
cmake_minimum_required(VERSION 3.24)
2+
project(tinyfseq C)
3+
4+
set(CMAKE_C_STANDARD 99)
5+
6+
enable_testing()
7+
8+
add_executable(test_build test/build.c)
9+
add_test(build test_build)
10+
11+
add_executable(test_TFError_string test/TFError_string.c)
12+
add_test(TFError_string test_TFError_string)
13+
14+
if (ENABLE_FUZZING)
15+
add_executable(fuzz_TFChannelRange_read fuzz/TFChannelRange_read.c)
16+
target_link_libraries(fuzz_TFChannelRange_read "-fsanitize=fuzzer")
17+
target_compile_options(fuzz_TFChannelRange_read PRIVATE "-fsanitize=fuzzer")
18+
19+
add_executable(fuzz_TFCompressionBlock_read fuzz/TFCompressionBlock_read.c)
20+
target_link_libraries(fuzz_TFCompressionBlock_read "-fsanitize=fuzzer")
21+
target_compile_options(fuzz_TFCompressionBlock_read PRIVATE "-fsanitize=fuzzer")
22+
23+
add_executable(fuzz_TFHeader_read fuzz/TFHeader_read.c)
24+
target_link_libraries(fuzz_TFHeader_read "-fsanitize=fuzzer")
25+
target_compile_options(fuzz_TFHeader_read PRIVATE "-fsanitize=fuzzer")
26+
endif ()

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A single-file library (~150 LOC) for decoding FSEQ (.fseq) v2.0+ sequence files
88
- `#include "tinyfseq.h"` as expected (you may need to modify the path).
99
- Define `TINYFSEQ_IMPLEMENTATION` in a single C/C++ source code file ([more info on using single-file libraries](https://github.com/nothings/stb#how-do-i-use-these-libraries))
1010

11-
A short example of including libtinyfseq and decoding a file header is available in [`example.c`](example.c)
11+
A short example of including libtinyfseq and printing the library version is available in the form of a [`test/build.c`](unit test).
1212

1313
## Compatibility
1414

example.c

Lines changed: 0 additions & 77 deletions
This file was deleted.

fuzz/TFChannelRange_read.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdio.h>
2+
3+
#define TINYFSEQ_IMPLEMENTATION
4+
#include "../tinyfseq.h"
5+
6+
int LLVMFuzzerTestOneInput(const uint8_t *data, const size_t size) {
7+
TFChannelRange range;
8+
TFChannelRange_read(data, size, &range, NULL);
9+
return 0;
10+
}

fuzz/TFCompressionBlock_read.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdio.h>
2+
3+
#define TINYFSEQ_IMPLEMENTATION
4+
#include "../tinyfseq.h"
5+
6+
int LLVMFuzzerTestOneInput(const uint8_t *data, const size_t size) {
7+
TFCompressionBlock block;
8+
TFCompressionBlock_read(data, size, &block, NULL);
9+
return 0;
10+
}

fuzz/TFHeader_read.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdio.h>
2+
3+
#define TINYFSEQ_IMPLEMENTATION
4+
#include "../tinyfseq.h"
5+
6+
int LLVMFuzzerTestOneInput(const uint8_t *data, const size_t size) {
7+
TFHeader header;
8+
TFHeader_read(data, size, &header, NULL);
9+
return 0;
10+
}

test/TFError_string.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#undef NDEBUG
2+
#include <assert.h>
3+
#include <limits.h>
4+
#include <stdio.h>
5+
#include <string.h>
6+
7+
#define TINYFSEQ_IMPLEMENTATION
8+
#include "../tinyfseq.h"
9+
10+
int main(const int argc, const char **argv) {
11+
(void) argc;
12+
(void) argv;
13+
14+
// no valid `TFError_string` parameter value should return a NULL or empty string
15+
for (uint8_t i = 0; i < UCHAR_MAX; i++) {
16+
assert(TFError_string(i) == NULL || strlen(TFError_string(i)) == 0);
17+
}
18+
19+
return 0;
20+
}

0 commit comments

Comments
 (0)