Coverage Report

Created: 2026-10-28 06:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/brunsli/c/tests/fuzz_decode.cc
Line
Count
Source
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 <tuple>
10
#include <vector>
11
12
// #include "testing/fuzzing/fuzztest.h"
13
#include <brunsli/brunsli_decode.h>
14
#include <brunsli/jpeg_data.h>
15
#include <brunsli/jpeg_data_writer.h>
16
#include <brunsli/status.h>
17
18
#include "../common/platform.h"
19
20
// clang-format off
21
#if !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
22
// #include "gtest/gtest.h"
23
#endif
24
#include "./test_utils.h"
25
// clang-format on
26
27
895
size_t DiscardOutputFunction(void* data, const uint8_t* buf, size_t count) {
28
895
  BRUNSLI_UNUSED(data);
29
895
  BRUNSLI_UNUSED(buf);
30
895
  return count;
31
895
}
32
33
17.4k
int DoTestOneInput(const uint8_t* data, size_t size) {
34
17.4k
  brunsli::JPEGOutput out(DiscardOutputFunction, nullptr);
35
17.4k
  brunsli::JPEGData jpg;
36
17.4k
  brunsli::BrunsliStatus status;
37
17.4k
  status = brunsli::BrunsliDecodeJpeg(data, size, &jpg);
38
17.4k
  if (status == brunsli::BRUNSLI_OK) {
39
4.49k
    brunsli::WriteJpeg(jpg, out);
40
4.49k
  }
41
17.4k
  return 0;
42
17.4k
}
43
44
// Entry point for LibFuzzer.
45
33.1k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
46
33.1k
  return DoTestOneInput(data, size);
47
33.1k
}
48
49
0
void TestOneInput(const std::vector<uint8_t>& data) {
50
0
  DoTestOneInput(data.data(), data.size());
51
0
}
52
53
0
std::vector<std::tuple<std::vector<uint8_t>>> ReadSeeds() {
54
0
  const std::vector<uint8_t> data = brunsli::ReadTestData("fuzz-decode.mar");
55
0
  return brunsli::ParseMar(data.data(), data.size());
56
0
}
57
58
FUZZ_TEST(BrunsliDecodeFuzz, TestOneInput).WithSeeds(ReadSeeds);
59
60
// TODO(eustas): Add existing cases.
61
0
TEST(BrunsliDecodeFuzz, Empty) { DoTestOneInput(nullptr, 0); }