• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 Google Inc.
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 //      http://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 ////////////////////////////////////////////////////////////////////////////////
16 
17 #include <cstdint>
18 #include <cstdio>
19 #include <string_view>
20 
21 #include "src/webp/decode.h"
22 #include "tests/fuzzer/fuzz_utils.h"
23 
24 namespace {
25 
DecodeWebP(std::string_view arbitrary_bytes)26 void DecodeWebP(std::string_view arbitrary_bytes) {
27   WebPDecoderConfig decoder_config;
28   if (!WebPInitDecoderConfig(&decoder_config)) {
29     fprintf(stderr, "WebPInitDecoderConfig failed.\n");
30     abort();
31   }
32   const VP8StatusCode status =
33       WebPDecode(reinterpret_cast<const uint8_t*>(arbitrary_bytes.data()),
34                  arbitrary_bytes.size(), &decoder_config);
35   WebPFreeDecBuffer(&decoder_config.output);
36   // The decoding may fail (because the fuzzed input can be anything) but not
37   // for these reasons.
38   if (status == VP8_STATUS_SUSPENDED || status == VP8_STATUS_USER_ABORT) {
39     abort();
40   }
41 }
42 
43 FUZZ_TEST(WebPSuite, DecodeWebP)
44     .WithDomains(
45         fuzztest::String()
46             .WithMaxSize(fuzz_utils::kMaxWebPFileSize + 1));
47 
48 }  // namespace
49