Skip to content

Commit 93a88b4

Browse files
authored
OSS-Fuzz integration updates (#219)
* fix build * CIFuzz integration * update fuzzer * undo changes to build * ossfuzz.sh: fix copy path
1 parent c17ea5d commit 93a88b4

3 files changed

Lines changed: 80 additions & 1 deletion

File tree

.github/workflows/ci-fuzz.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: CIFuzz
2+
on: [pull_request]
3+
jobs:
4+
Fuzzing:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Build Fuzzers
8+
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
9+
with:
10+
oss-fuzz-project-name: 'utf8proc'
11+
dry-run: false
12+
- name: Run Fuzzers
13+
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
14+
with:
15+
oss-fuzz-project-name: 'utf8proc'
16+
fuzz-seconds: 600
17+
dry-run: false
18+
- name: Upload Crash
19+
uses: actions/upload-artifact@v1
20+
if: failure()
21+
with:
22+
name: artifacts
23+
path: ./out/artifacts

test/fuzzer.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,67 @@
11
#include <utf8proc.h>
2+
#include <string.h>
23

34
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
45
{
56
if(size < 1) return 0;
67

78
if(data[size-1] != '\0') return 0;
89

10+
const uint8_t* ptr = data;
11+
utf8proc_int32_t c = 0;
12+
utf8proc_option_t options;
13+
utf8proc_ssize_t ret, bytes = 0;
14+
size_t len = strlen((const char*)data);
15+
16+
while(bytes != len)
17+
{
18+
ret = utf8proc_iterate(ptr, -1, &c);
19+
20+
if(ret < 0 || ret == 0) break;
21+
22+
bytes += ret;
23+
ptr += ret;
24+
25+
utf8proc_tolower(c);
26+
utf8proc_toupper(c);
27+
utf8proc_totitle(c);
28+
utf8proc_islower(c);
29+
utf8proc_isupper(c);
30+
utf8proc_charwidth(c);
31+
utf8proc_category(c);
32+
utf8proc_category_string(c);
33+
utf8proc_codepoint_valid(c);
34+
}
35+
36+
utf8proc_int32_t *copy = size >= 4 ? NULL : malloc(size);
37+
38+
if(copy)
39+
{
40+
size /= 4;
41+
42+
options = UTF8PROC_STRIPCC | UTF8PROC_NLF2LS | UTF8PROC_NLF2PS;
43+
memcpy(copy, data, size);
44+
utf8proc_normalize_utf32(copy, size, options);
45+
46+
options = UTF8PROC_STRIPCC | UTF8PROC_NLF2LS;
47+
memcpy(copy, data, size);
48+
utf8proc_normalize_utf32(copy, size, options);
49+
50+
options = UTF8PROC_STRIPCC | UTF8PROC_NLF2PS;
51+
memcpy(copy, data, size);
52+
utf8proc_normalize_utf32(copy, size, options);
53+
54+
options = UTF8PROC_STRIPCC;
55+
memcpy(copy, data, size);
56+
utf8proc_normalize_utf32(copy, size, options);
57+
58+
options = 0;
59+
memcpy(copy, data, size);
60+
utf8proc_normalize_utf32(copy, size, options);
61+
62+
free(copy);
63+
}
64+
965
free(utf8proc_NFD(data));
1066
free(utf8proc_NFC(data));
1167
free(utf8proc_NFKD(data));

test/ossfuzz.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cd build
77
cmake .. -DUTF8PROC_ENABLE_TESTING=ON -DLIB_FUZZING_ENGINE="$LIB_FUZZING_ENGINE"
88
make -j$(nproc)
99

10-
cp $SRC/utf8proc/build/fuzzer utf8proc_fuzzer
10+
cp $SRC/utf8proc/build/fuzzer $OUT/utf8proc_fuzzer
1111

1212
find $SRC/utf8proc/test -name "*.txt" | \
1313
xargs zip $OUT/utf8proc_fuzzer_seed_corpus.zip

0 commit comments

Comments
 (0)