1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // ASTC fuzzing wrapper to help with fuzz testing.
16
17 #include "src/decoder/codec.h"
18
19 #include <benchmark/benchmark.h>
20
21 #include <vector>
22
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)23 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
24 std::string error;
25 std::unique_ptr<astc_codec::ASTCFile> file =
26 astc_codec::ASTCFile::LoadFromMemory(reinterpret_cast<const char*>(data),
27 size, &error);
28 if (file) {
29 std::vector<uint8_t> out_buffer(file->GetWidth() * file->GetHeight() * 4);
30 bool result = astc_codec::DecompressToImage(
31 *file, out_buffer.data(), out_buffer.size(), file->GetWidth() * 4);
32 benchmark::DoNotOptimize(result);
33 }
34
35 return 0;
36 }
37