go-libwebp

Experimental translation from libwebp to Go source.
Log | Files | Refs | README | LICENSE

dec_fuzzer.cc (1617B)


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