File tree Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,11 @@ write_basic_package_version_file(${PROJECT_NAME}-config-version.cmake
109
109
#pkg-config file
110
110
configure_file (${PROJECT_NAME} .pc.in ${LIBRARY_NAME} .pc @ONLY)
111
111
112
+ if (DEFINED ENV{LIB_FUZZING_ENGINE})
113
+ add_executable (fuzz_ParseFromString fuzzer/fuzz_ParseFromString.cc)
114
+ target_link_libraries (fuzz_ParseFromString ${LIBRARY_NAME} $ENV{LIB_FUZZING_ENGINE} )
115
+ endif ()
116
+
112
117
#Installation
113
118
install (TARGETS
114
119
${LIBRARY_NAME}
Original file line number Diff line number Diff line change
1
+ # Fuzzing test
2
+
3
+ Do fuzzing test for tinyobjloader
4
+
5
+ ## Supported API
6
+
7
+ * [x] ParseFromString
8
+
9
+ ## Requirements
10
+
11
+ * clang with fuzzer support(` -fsanitize=fuzzer ` . at least clang 8.0 should work)
12
+
13
+ ## Setup
14
+
15
+ ### Ubuntu 18.04
16
+
17
+ ```
18
+ $ sudo apt install clang++-8
19
+ $ sudo apt install libfuzzer-8-dev
20
+ ```
21
+
22
+ Optionally, if you didn't set ` update-alternatives ` you can set ` clang++ ` to point to ` clang++8 `
23
+
24
+ ```
25
+ $ sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-8 10
26
+ $ sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-8 10
27
+ ```
28
+
29
+ ## How to compile
30
+
31
+ Fuzz target is compiled with the rest of the project when environment variable ` LIB_FUZZING_ENGINE ` is defined when running cmake
32
+ With clang, you can compile with
33
+ ```
34
+ $ export LIB_FUZZING_ENGINE=-fsanitize=fuzzer
35
+ $ mkdir build && cd build
36
+ $ cmake .. -DBUILD_SHARED_LIBS=OFF
37
+ $ make -j $(nproc)
38
+ ```
39
+
40
+ ## How to run
41
+
42
+ Increase memory limit. e.g. ` -rss_limit_mb=2000 `
43
+ cf libfuzzer.info for all options
44
+
45
+ ```
46
+ $ ./fuzz_ParseFromString -rss_limit_mb=2000
47
+ ```
Original file line number Diff line number Diff line change
1
+ #include < stdio.h>
2
+ #include < stdlib.h>
3
+ #include < stdint.h>
4
+ #include < stdarg.h>
5
+ #include < string.h>
6
+
7
+ #define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc
8
+ #include " tiny_obj_loader.h"
9
+
10
+ extern " C" int LLVMFuzzerTestOneInput (const uint8_t *Data, size_t Size) {
11
+ tinyobj::ObjReaderConfig reader_config;
12
+ tinyobj::ObjReader reader;
13
+ if (Size < 2 ) {
14
+ return 0 ;
15
+ }
16
+ for (size_t i = 0 ; i < Size-1 ; i++) {
17
+ if (Data[i] == 0 ) {
18
+ std::string obj_text (reinterpret_cast <const char *>(Data), i);
19
+ std::string mtl_text (reinterpret_cast <const char *>(Data+i+1 ), Size-i-1 );
20
+ reader.ParseFromString (obj_text, mtl_text,reader_config);
21
+ return 0 ;
22
+ }
23
+ }
24
+ return 0 ;
25
+ }
26
+
You can’t perform that action at this time.
0 commit comments