Coverage Report

Created: 2026-03-31 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dcmtk-fuzzers/dcmtk_meta_fuzzer.cc
Line
Count
Source
1
// Copyright 2026 Google LLC
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 <cstddef>
19
#include <new>
20
21
#include "dcmtk/dcmdata/dcmetinf.h"
22
#include "dcmtk/dcmdata/dcistrmb.h"
23
#include "dcmtk/dcmdata/dcdeftag.h"
24
#include "dcmtk/dcmdata/dcxfer.h"
25
26
static constexpr std::size_t kNewCap = 2 * 1024 * 1024;
27
0
void* operator new(std::size_t n, const std::nothrow_t&) noexcept {
28
0
  if (n > kNewCap) return nullptr;
29
0
  try { return ::operator new(n); } catch (...) { return nullptr; }
30
0
}
31
0
void* operator new[](std::size_t n, const std::nothrow_t&) noexcept {
32
0
  if (n > kNewCap) return nullptr;
33
0
  try { return ::operator new[](n); } catch (...) { return nullptr; }
34
0
}
35
36
16
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
37
16
  DcmInputBufferStream in;
38
16
  in.setBuffer((void*)data, size);
39
16
  in.setEos();
40
41
16
  DcmMetaInfo mi;
42
16
  const Uint32 kMaxReadLen = 128 * 1024;
43
16
  if (mi.read(in, EXS_LittleEndianExplicit, EGL_noChange, kMaxReadLen).good()) {
44
16
    OFString s;
45
16
    (void)mi.findAndGetOFString(DCM_TransferSyntaxUID, s);
46
16
    (void)mi.findAndGetOFString(DCM_SourceApplicationEntityTitle, s);
47
16
  }
48
16
  return 0;
49
16
}