mirror of
https://github.com/minetest/irrlicht.git
synced 2025-07-06 10:10:25 +02:00
Blindly dump tinygltf in like a neanderthal
This commit is contained in:
46
source/lib/tinygltf/tests/fuzzer/README.md
Normal file
46
source/lib/tinygltf/tests/fuzzer/README.md
Normal file
@ -0,0 +1,46 @@
|
||||
# Fuzzing test
|
||||
|
||||
Do fuzzing test for TinyGLTF API.
|
||||
|
||||
## Supported API
|
||||
|
||||
* [x] LoadASCIIFromMemory
|
||||
* [ ] LoadBinaryFromMemory
|
||||
|
||||
## Requirements
|
||||
|
||||
* meson
|
||||
* clang with fuzzer support(`-fsanitize=fuzzer`. at least clang 8.0 should work)
|
||||
|
||||
## Setup
|
||||
|
||||
### Ubuntu 18.04
|
||||
|
||||
```
|
||||
$ sudo apt install clang++-8
|
||||
$ sudo apt install libfuzzer-8-dev
|
||||
```
|
||||
|
||||
Optionally, if you didn't set `update-alternatives` you can set `clang++` to point to `clang++8`
|
||||
|
||||
```
|
||||
$ sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-8 10
|
||||
$ sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-8 10
|
||||
```
|
||||
|
||||
## How to compile
|
||||
|
||||
```
|
||||
$ CXX=clang++ CC=clang meson build
|
||||
$ cd build
|
||||
$ ninja
|
||||
```
|
||||
|
||||
## How to run
|
||||
|
||||
Increase memory limit. e.g. `-rss_limit_mb=50000`
|
||||
|
||||
```
|
||||
$ ./fuzz_gltf -rss_limit_mb=20000 -jobs 4
|
||||
```
|
||||
|
33
source/lib/tinygltf/tests/fuzzer/fuzz_gltf.cc
Normal file
33
source/lib/tinygltf/tests/fuzzer/fuzz_gltf.cc
Normal file
@ -0,0 +1,33 @@
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#define TINYGLTF_IMPLEMENTATION
|
||||
#include "tiny_gltf.h"
|
||||
|
||||
static void parse_intCoding4(const uint8_t *data, size_t size)
|
||||
{
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
const char *str = reinterpret_cast<const char *>(data);
|
||||
|
||||
bool ret = ctx.LoadASCIIFromString(&model, &err, &warn, str, size, /* base_dir */"" );
|
||||
(void)ret;
|
||||
|
||||
}
|
||||
|
||||
extern "C"
|
||||
int LLVMFuzzerTestOneInput(std::uint8_t const* data, std::size_t size)
|
||||
{
|
||||
parse_intCoding4(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
9
source/lib/tinygltf/tests/fuzzer/meson.build
Normal file
9
source/lib/tinygltf/tests/fuzzer/meson.build
Normal file
@ -0,0 +1,9 @@
|
||||
project('fuzz_tinygltf', 'cpp', default_options : ['cpp_std=c++11'])
|
||||
|
||||
incdirs = include_directories('../../')
|
||||
executable('fuzz_gltf',
|
||||
'fuzz_gltf.cc',
|
||||
include_directories : incdirs,
|
||||
cpp_args : '-fsanitize=address,fuzzer',
|
||||
link_args : '-fsanitize=address,fuzzer' )
|
||||
|
Reference in New Issue
Block a user