/src/gfwx-fuzzers/decoder.cpp
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* By Guido Vranken <guidovranken@gmail.com> */  | 
2  |  |  | 
3  |  | #include <cstdint>  | 
4  |  | #include <cstddef>  | 
5  |  | #include <cstring>  | 
6  |  | #include <cmath>  | 
7  |  | #include "gfwx.h"  | 
8  |  | #include "fuzzing/memory.hpp"  | 
9  |  |  | 
10  |  | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)  | 
11  | 15  | { | 
12  | 15  |     GFWX::Header header;  | 
13  |  |  | 
14  | 15  |     { | 
15  | 15  |         ptrdiff_t result = GFWX::decompress((uint8_t*)0, header, data, size, 0, true);  | 
16  | 15  |         if (result != GFWX::ResultOk) { | 
17  | 4  |             return 0;  | 
18  | 4  |         }  | 
19  | 15  |     }  | 
20  |  |  | 
21  | 11  |     if ( header.bitDepth > 32 ) { | 
22  | 0  |         return 0;  | 
23  | 0  |     }  | 
24  | 11  |     if ( header.channels > 10 ) { | 
25  | 0  |         return 0;  | 
26  | 0  |     }  | 
27  | 11  |     if ( header.layers > 10 ) { | 
28  | 0  |         return 0;  | 
29  | 0  |     }  | 
30  | 11  |     if ( header.sizex > 10240 ) { | 
31  | 0  |         return 0;  | 
32  | 0  |     }  | 
33  | 11  |     if ( header.sizey > 10240 ) { | 
34  | 0  |         return 0;  | 
35  | 0  |     }  | 
36  |  |  | 
37  | 11  |     { | 
38  | 11  |         const size_t totalOutSize = (header.bitDepth / 8) * header.channels * header.layers * header.sizex * header.sizey;  | 
39  | 11  |         if ( totalOutSize > (1024*1024) ) { | 
40  | 0  |             return 0;  | 
41  | 0  |         }  | 
42  | 11  |         std::vector<uint8_t> out(totalOutSize);  | 
43  | 11  |         ptrdiff_t result = GFWX::decompress(out.data(), header, data, size, 0, false);  | 
44  | 11  |         if (result != GFWX::ResultOk) { | 
45  | 10  |             return 0;  | 
46  | 10  |         }  | 
47  | 1  |         fuzzing::memory::memory_test(out);  | 
48  | 1  |     }  | 
49  |  |  | 
50  | 0  |     return 0;  | 
51  | 11  | }  |