Coverage Report

Created: 2024-09-08 06:07

/src/brunsli/c/tests/fuzz_decode.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) Google LLC 2019
2
//
3
// Use of this source code is governed by an MIT-style
4
// license that can be found in the LICENSE file or at
5
// https://opensource.org/licenses/MIT.
6
7
#include <cstddef>
8
#include <cstdint>
9
#include <vector>
10
11
// #include "gtest/gtest.h"
12
// #include "testing/fuzzing/fuzztest.h"
13
#include <brunsli/jpeg_data.h>
14
#include "../common/platform.h"
15
#include <brunsli/status.h>
16
#include <brunsli/brunsli_decode.h>
17
#include <brunsli/jpeg_data_writer.h>
18
#include "./test_utils.h"
19
20
694
size_t DiscardOutputFunction(void* data, const uint8_t* buf, size_t count) {
21
694
  BRUNSLI_UNUSED(data);
22
694
  BRUNSLI_UNUSED(buf);
23
694
  return count;
24
694
}
25
26
11.2k
int DoTestOneInput(const uint8_t* data, size_t size) {
27
11.2k
  brunsli::JPEGOutput out(DiscardOutputFunction, nullptr);
28
11.2k
  brunsli::JPEGData jpg;
29
11.2k
  brunsli::BrunsliStatus status;
30
11.2k
  status = brunsli::BrunsliDecodeJpeg(data, size, &jpg);
31
11.2k
  if (status == brunsli::BRUNSLI_OK) {
32
2.56k
    brunsli::WriteJpeg(jpg, out);
33
2.56k
  }
34
11.2k
  return 0;
35
11.2k
}
36
37
// Entry point for LibFuzzer.
38
21.7k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
39
21.7k
  return DoTestOneInput(data, size);
40
21.7k
}
41
42
0
void TestOneInput(const std::vector<uint8_t>& data) {
43
0
  DoTestOneInput(data.data(), data.size());
44
0
}
45
46
0
std::vector<std::tuple<std::vector<uint8_t>>> ReadSeeds() {
47
0
  const std::vector<uint8_t> data = brunsli::ReadTestData("fuzz-decode.mar");
48
0
  return brunsli::ParseMar(data.data(), data.size());
49
0
}
50
51
FUZZ_TEST(BrunsliDecodeFuzz, TestOneInput).WithSeeds(ReadSeeds);
52
53
// TODO(eustas): Add existing cases.
54
0
TEST(BrunsliDecodeFuzz, Empty) {
55
0
  DoTestOneInput(nullptr, 0);
56
0
}