Coverage Report

Created: 2025-10-10 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavif/tests/gtest/avif_fuzztest_dec.cc
Line
Count
Source
1
// Copyright 2023 Google LLC
2
// SPDX-License-Identifier: BSD-2-Clause
3
// Decodes an arbitrary sequence of bytes.
4
5
#include <algorithm>
6
#include <cstdint>
7
8
#include "avif/avif.h"
9
#include "avif_fuzztest_helpers.h"
10
#include "aviftest_helpers.h"
11
#include "fuzztest/fuzztest.h"
12
#include "gtest/gtest.h"
13
14
using ::fuzztest::Arbitrary;
15
16
namespace avif {
17
namespace testutil {
18
namespace {
19
20
//------------------------------------------------------------------------------
21
22
void Decode(const std::string& arbitrary_bytes, bool is_persistent,
23
21.8k
            DecoderPtr decoder) {
24
21.8k
  ASSERT_FALSE(GetSeedDataDirs().empty());  // Make sure seeds are available.
25
26
21.8k
  ImagePtr decoded(avifImageCreateEmpty());
27
21.8k
  ASSERT_NE(decoded, nullptr);
28
29
21.8k
  const uint8_t* data =
30
21.8k
      reinterpret_cast<const uint8_t*>(arbitrary_bytes.data());
31
21.8k
  avifIO* const io = avifIOCreateMemoryReader(data, arbitrary_bytes.size());
32
21.8k
  if (io == nullptr) return;
33
  // The Chrome's avifIO object is not persistent.
34
21.8k
  io->persistent = is_persistent;
35
21.8k
  avifDecoderSetIO(decoder.get(), io);
36
37
21.8k
  if (avifDecoderParse(decoder.get()) != AVIF_RESULT_OK) return;
38
39
36.4k
  for (size_t i = 0; i < decoder->image->numProperties; ++i) {
40
17.3k
    const avifRWData& box_payload = decoder->image->properties[i].boxPayload;
41
    // Each custom property should be found as is in the input bitstream.
42
17.3k
    EXPECT_NE(std::search(data, data + arbitrary_bytes.size(), box_payload.data,
43
17.3k
                          box_payload.data + box_payload.size),
44
17.3k
              data + arbitrary_bytes.size());
45
17.3k
  }
46
47
23.9k
  while (avifDecoderNextImage(decoder.get()) == AVIF_RESULT_OK) {
48
4.82k
    EXPECT_GT(decoder->image->width, 0u);
49
4.82k
    EXPECT_GT(decoder->image->height, 0u);
50
4.82k
  }
51
52
  // Loop once.
53
19.0k
  if (avifDecoderReset(decoder.get()) != AVIF_RESULT_OK) return;
54
20.8k
  while (avifDecoderNextImage(decoder.get()) == AVIF_RESULT_OK) {
55
3.47k
  }
56
17.4k
}
57
58
FUZZ_TEST(DecodeAvifTest, Decode)
59
    .WithDomains(ArbitraryImageWithSeeds({AVIF_APP_FILE_FORMAT_AVIF}),
60
                 Arbitrary<bool>(), ArbitraryAvifDecoder());
61
62
//------------------------------------------------------------------------------
63
64
}  // namespace
65
}  // namespace testutil
66
}  // namespace avif