Coverage Report

Created: 2026-08-14 08:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjxl/tools/decode_basic_info_fuzzer.cc
Line
Count
Source
1
// Copyright (c) the JPEG XL Project Authors. All rights reserved.
2
//
3
// Use of this source code is governed by a BSD-style
4
// license that can be found in the LICENSE file.
5
6
#include <jxl/codestream_header.h>
7
#include <jxl/decode.h>
8
9
#include <cstddef>
10
#include <cstdint>
11
#include <cstdio>
12
#include <vector>
13
14
#include "lib/jxl/fuzztest.h"
15
#include "tools/tracking_memory_manager.h"
16
17
namespace {
18
19
using ::jpegxl::tools::kGiB;
20
using ::jpegxl::tools::TrackingMemoryManager;
21
22
0
void CheckImpl(bool ok, const char* condition, const char* file, int line) {
23
0
  if (!ok) {
24
0
    fprintf(stderr, "Check(%s) failed at %s:%d\n", condition, file, line);
25
0
    __builtin_trap();
26
0
  }
27
0
}
28
0
#define Check(OK) CheckImpl((OK), #OK, __FILE__, __LINE__)
29
30
0
int DoTestOneInput(const uint8_t* data, size_t size) {
31
0
  JxlDecoderStatus status;
32
0
  TrackingMemoryManager memory_manager{/* cap */ 1 * kGiB,
33
0
                                       /* total_cap */ 5 * kGiB};
34
0
  JxlDecoder* dec = JxlDecoderCreate(memory_manager.get());
35
0
  const auto finish = [&]() -> int {
36
0
    JxlDecoderDestroy(dec);
37
0
    Check(memory_manager.Reset());
38
0
    return 0;
39
0
  };
40
41
0
  JxlDecoderSubscribeEvents(dec, JXL_DEC_BASIC_INFO | JXL_DEC_COLOR_ENCODING);
42
0
  JxlDecoderSetInput(dec, data, size);
43
44
0
  status = JxlDecoderProcessInput(dec);
45
46
0
  if (status != JXL_DEC_BASIC_INFO) return finish();
47
48
0
  JxlBasicInfo info;
49
0
  status = JxlDecoderGetBasicInfo(dec, &info);
50
0
  bool have_basic_info = (status == JXL_DEC_SUCCESS);
51
52
0
  if (have_basic_info) {
53
0
    if (info.alpha_bits != 0) {
54
0
      for (int i = 0; i < info.num_extra_channels; ++i) {
55
0
        JxlExtraChannelInfo extra;
56
0
        JxlDecoderGetExtraChannelInfo(dec, 0, &extra);
57
0
      }
58
0
    }
59
0
  }
60
0
  status = JxlDecoderProcessInput(dec);
61
62
0
  if (status != JXL_DEC_COLOR_ENCODING) return finish();
63
64
0
  JxlDecoderGetColorAsEncodedProfile(dec, JXL_COLOR_PROFILE_TARGET_ORIGINAL,
65
0
                                     nullptr);
66
0
  size_t dec_profile_size;
67
0
  JxlDecoderGetICCProfileSize(dec, JXL_COLOR_PROFILE_TARGET_ORIGINAL,
68
0
                              &dec_profile_size);
69
70
0
  return finish();
71
0
}
72
73
}  // namespace
74
75
54.6k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
76
54.6k
  return DoTestOneInput(data, size);
77
54.6k
}
78
79
0
void TestOneInput(const std::vector<uint8_t>& data) {
80
0
  DoTestOneInput(data.data(), data.size());
81
0
}
82
83
FUZZ_TEST(DecodeBasicInfoFuzzTest, TestOneInput);