Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fuzz_parser.cpp
Go to the documentation of this file.
1#include <sysio/wasm_backend/parser.hpp>
2#include <fstream>
3#include <iostream>
4#include <chrono>
5
6using namespace sysio;
7using namespace sysio::wasm_backend;
8using namespace std::chrono;
9
10
11std::vector<uint8_t> read_wasm( const std::string& fname ) {
12 std::ifstream wasm_file(fname, std::ios::binary);
13 FC_ASSERT( wasm_file.is_open(), "wasm file cannot be found" );
14 wasm_file.seekg(0, std::ios::end);
15 std::vector<uint8_t> wasm;
16 int len = wasm_file.tellg();
17 FC_ASSERT( len >= 0, "wasm file length is -1" );
18 wasm.resize(len);
19 wasm_file.seekg(0, std::ios::beg);
20 wasm_file.read((char*)wasm.data(), wasm.size());
21 wasm_file.close();
22 return wasm;
23}
24//extern "C" int LLVMFuzzerTestOneInput( const uint8_t* data, size_t size ) {
25// binary_parser bp;
26// module mod;
27// memory_manager::set_memory_limits( 128*1024, 64*1024 );
28// wasm_code test;
29// test.resize( size );
30// memcpy( (char*)test.data(), data, size );
31// bp.parse_module( test, mod );
32//}
33
34int main( int argc, const char* argv[] ) {
35 high_resolution_clock::time_point start;
36 try {
37 memory_manager::set_memory_limits( 128*1024, 64*1024 );
38 binary_parser bp;
39 module mod;
40 wasm_code test = read_wasm(argv[1]);
41 start = high_resolution_clock::now();
42 bp.parse_module( test, mod );
43 } catch (fc::exception& e) {
44 std::cout << "FAIL : " << e.what() <<"\n";
45 }
46 auto stop = high_resolution_clock::now();
47 auto duration = duration_cast<microseconds>(stop - start);
48 std::cout << "TIME : " << duration.count() << "us\n";
49
50#if 0
51 catch ( wasm_parse_exception& ex ) {
52 } catch ( wasm_interpreter_exception& ex ) {
53 } catch ( wasm_section_length_exception& ex ) {
54 } catch ( wasm_bad_alloc& ex ) {
55 } catch ( wasm_double_free& ex ) {
56 } catch ( wasm_vector_oob_exception& ex ) {
57 } catch ( wasm_memory_exception& ex ) {
58 } catch ( wasm_unsupported_import_exception& ex ) {
59 } catch ( wasm_illegal_opcode_exception& ex ) {
60 } catch ( guarded_ptr_exception& ex ) {
61 }
62#endif
63}
Used to generate a useful error report when an exception is thrown.
Definition exception.hpp:58
const char * what() const noexcept override
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
std::vector< uint8_t > read_wasm(const std::string &fname)
char ** argv
size_t len