Coverage Report

Created: 2025-10-10 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/upx/fuzzers/decompress_packed_file_fuzzer.cpp
Line
Count
Source
1
/* Copyright 2023 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
13
#include <stddef.h>
14
#include <stdint.h>
15
#include <stdio.h>
16
17
#include "../src/conf.h"
18
#include "../src/file.h"
19
#include "../src/packmast.h"
20
21
enum OpenMode { RO_MUST_EXIST, WO_MUST_EXIST_TRUNCATE, WO_MUST_CREATE, WO_CREATE_OR_TRUNCATE };
22
23
25.4k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
24
25.4k
  char infilename[256];
25
25.4k
  char outfilename[256];
26
25.4k
  snprintf(infilename, 256, "/tmp/libfuzzer.%d", getpid());
27
25.4k
  snprintf(outfilename, 256, "/tmp/libfuzzer.%d.decompressed", getpid());
28
  
29
25.4k
  FILE *fp = fopen(infilename, "wb");
30
25.4k
  if (!fp) {
31
0
    return 0;
32
0
  }
33
25.4k
  fwrite(data, size, 1, fp);
34
25.4k
  fclose(fp);
35
36
25.4k
  char argv_progname[4] = "upx";
37
25.4k
  char argv_decompression[3] = "-d";
38
25.4k
  char argv_output[3] = "-o";
39
40
25.4k
  char* argv_data[] = {argv_progname, argv_decompression, infilename, argv_output, outfilename};
41
42
25.4k
  try {
43
25.4k
    upx_main(5, argv_data);
44
25.4k
  } catch(...) {
45
0
  }
46
  
47
25.4k
  unlink(infilename);
48
25.4k
  unlink(outfilename);
49
25.4k
  return 0;
50
25.4k
}