Coverage Report

Created: 2025-01-23 06:31

/src/dng_camera_profile_fuzzer.cpp
Line
Count
Source (jump to first uncovered line)
1
/* Copyright 2021 Google LLC
2
Licensed under the Apache License, Version 2.0 (the "License");
3
you may not use this file except in compliance with the License.
4
You may obtain a copy of the License at
5
      http://www.apache.org/licenses/LICENSE-2.0
6
Unless required by applicable law or agreed to in writing, software
7
distributed under the License is distributed on an "AS IS" BASIS,
8
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
See the License for the specific language governing permissions and
10
limitations under the License.
11
*/
12
#include <stddef.h>
13
#include <stdint.h>
14
#include <stdio.h>
15
#include <stdlib.h>
16
#include <sys/types.h>
17
#include <unistd.h>
18
19
#include "dng_color_space.h"
20
#include "dng_date_time.h"
21
#include "dng_exceptions.h"
22
#include "dng_file_stream.h"
23
#include "dng_globals.h"
24
#include "dng_host.h"
25
#include "dng_ifd.h"
26
#include "dng_image_writer.h"
27
#include "dng_info.h"
28
#include "dng_linearization_info.h"
29
#include "dng_mosaic_info.h"
30
#include "dng_negative.h"
31
#include "dng_preview.h"
32
#include "dng_render.h"
33
#include "dng_simple_image.h"
34
#include "dng_tag_codes.h"
35
#include "dng_tag_types.h"
36
#include "dng_tag_values.h"
37
#include "dng_camera_profile.h"
38
39
#include <fuzzer/FuzzedDataProvider.h>
40
41
841
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
42
841
  FuzzedDataProvider provider(data, size);
43
841
  std::string s1 = provider.ConsumeRandomLengthString();
44
45
841
  char filename[256];
46
841
  sprintf(filename, "/tmp/libfuzzer.%d", getpid());
47
841
  FILE *fp = fopen(filename, "wb");
48
841
  if (!fp) {
49
0
      return 0;
50
0
  }
51
841
  fwrite(s1.c_str(), s1.size(), 1, fp);
52
841
  fclose(fp);
53
  
54
  // Create a file stream
55
841
  dng_file_stream fStream(filename, false, 0);
56
57
  // Create a custom camera profile based on the fstream above
58
841
  try {
59
841
    AutoPtr<dng_camera_profile> customCameraProfile (new dng_camera_profile ());
60
841
    customCameraProfile->ParseExtended(fStream);
61
62
    // The profile is not stubeed, so we can calculate the fingerprint.
63
841
    const dng_fingerprint &fPrint = customCameraProfile->Fingerprint();
64
841
  } catch (dng_exception &e) {}
65
66
841
  unlink(filename);
67
841
  return 0;
68
841
}