Coverage Report

Created: 2024-07-27 06:12

/src/lzma-fuzz/common-alloc.h
Line
Count
Source (jump to first uncovered line)
1
/**
2
 *
3
 * @copyright Copyright (c) 2019 Joachim Bauch <mail@joachim-bauch.de>
4
 *
5
 * @license GNU GPL version 3 or any later version
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
 *
20
 */
21
22
#include <stdint.h>
23
#include <stdlib.h>
24
25
#include "7zAlloc.h"
26
#include "7zTypes.h"
27
28
#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
29
30
// Arbitrary limit of 2 GByte for memory allocations. Used to prevent the
31
// MemorySanitizer from aborting with errors like "requested allocation size
32
// 0xffffffffffffffff exceeds maximum supported size of 0x200000000".
33
static const size_t kMaxAllowedMemory = 2 * 1024 * 1024 * 1024L;
34
35
10.3k
static void *LzmaAlloc(ISzAllocPtr p, size_t size) {
36
10.3k
  if (size > kMaxAllowedMemory) {
37
0
    return nullptr;
38
0
  }
39
40
10.3k
  return SzAlloc(nullptr, size);
41
10.3k
}
42
43
20.7k
static void LzmaFree(ISzAllocPtr p, void *address) {
44
20.7k
  SzFree(nullptr, address);
45
20.7k
}
46
47
static ISzAlloc CommonAlloc = {LzmaAlloc, LzmaFree};
48
49
#else
50
51
#include "7zAlloc.h"
52
53
static ISzAlloc CommonAlloc = {SzAlloc, SzFree};
54
55
#endif