Coverage Report

Created: 2025-06-16 07:00

/src/imagemagick/oss-fuzz/utils.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
  Copyright @ 2018 ImageMagick Studio LLC, a non-profit organization
3
  dedicated to making software imaging solutions freely available.
4
5
  You may not use this file except in compliance with the License.  You may
6
  obtain a copy of the License at
7
8
    https://imagemagick.org/script/license.php
9
10
  Unless required by applicable law or agreed to in writing, software
11
  distributed under the License is distributed on an "AS IS" BASIS,
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
  See the License for the specific language governing permissions and
14
  limitations under the License.
15
*/
16
17
#include <Magick++/Functions.h>
18
#include <Magick++/ResourceLimits.h>
19
#include <Magick++/SecurityPolicy.h>
20
21
#ifndef FUZZ_MAX_SIZE
22
584
#define FUZZ_MAX_SIZE 2048
23
#endif
24
25
static bool IsInvalidSize(const size_t size,const size_t min = 1)
26
725k
{
27
725k
  if (size < min)
28
0
    return(true);
29
725k
  if (size > 8192)
30
1.79k
    return(true);
31
723k
  return(false);
32
725k
}
encoder_fuzzer.cc:IsInvalidSize(unsigned long, unsigned long)
Line
Count
Source
26
657k
{
27
657k
  if (size < min)
28
0
    return(true);
29
657k
  if (size > 8192)
30
1.70k
    return(true);
31
656k
  return(false);
32
657k
}
encoder_plasma_fuzzer.cc:IsInvalidSize(unsigned long, unsigned long)
Line
Count
Source
26
4.04k
{
27
4.04k
  if (size < min)
28
0
    return(true);
29
4.04k
  if (size > 8192)
30
10
    return(true);
31
4.03k
  return(false);
32
4.04k
}
ping_fuzzer.cc:IsInvalidSize(unsigned long, unsigned long)
Line
Count
Source
26
37.6k
{
27
37.6k
  if (size < min)
28
0
    return(true);
29
37.6k
  if (size > 8192)
30
1
    return(true);
31
37.6k
  return(false);
32
37.6k
}
encoder_gradient_fuzzer.cc:IsInvalidSize(unsigned long, unsigned long)
Line
Count
Source
26
3.90k
{
27
3.90k
  if (size < min)
28
0
    return(true);
29
3.90k
  if (size > 8192)
30
15
    return(true);
31
3.88k
  return(false);
32
3.90k
}
huffman_decode_fuzzer.cc:IsInvalidSize(unsigned long, unsigned long)
Line
Count
Source
26
42
{
27
42
  if (size < min)
28
0
    return(true);
29
42
  if (size > 8192)
30
16
    return(true);
31
26
  return(false);
32
42
}
encoder_xc_fuzzer.cc:IsInvalidSize(unsigned long, unsigned long)
Line
Count
Source
26
3.62k
{
27
3.62k
  if (size < min)
28
0
    return(true);
29
3.62k
  if (size > 8192)
30
12
    return(true);
31
3.61k
  return(false);
32
3.62k
}
encoder_pattern_fuzzer.cc:IsInvalidSize(unsigned long, unsigned long)
Line
Count
Source
26
3.83k
{
27
3.83k
  if (size < min)
28
0
    return(true);
29
3.83k
  if (size > 8192)
30
10
    return(true);
31
3.82k
  return(false);
32
3.83k
}
encoder_label_fuzzer.cc:IsInvalidSize(unsigned long, unsigned long)
Line
Count
Source
26
10.5k
{
27
10.5k
  if (size < min)
28
0
    return(true);
29
10.5k
  if (size > 8192)
30
9
    return(true);
31
10.5k
  return(false);
32
10.5k
}
encoder_radial-gradient_fuzzer.cc:IsInvalidSize(unsigned long, unsigned long)
Line
Count
Source
26
4.00k
{
27
4.00k
  if (size < min)
28
0
    return(true);
29
4.00k
  if (size > 8192)
30
13
    return(true);
31
3.98k
  return(false);
32
4.00k
}
33
34
class FuzzingInitializer
35
{
36
public:
37
  FuzzingInitializer()
38
584
  {
39
    // Disable SIMD in jpeg turbo.
40
584
    (void) putenv(const_cast<char *>("JSIMD_FORCENONE=1"));
41
42
584
    Magick::InitializeMagick((const char *) NULL);
43
584
    Magick::SecurityPolicy::anonymousCacheMemoryMap();
44
584
    Magick::SecurityPolicy::anonymousSystemMemoryMap();
45
584
    Magick::SecurityPolicy::maxMemoryRequest(128000000);
46
584
    Magick::ResourceLimits::memory(1000000000);
47
584
    Magick::ResourceLimits::map(500000000);
48
584
    Magick::ResourceLimits::width(FUZZ_MAX_SIZE);
49
584
    Magick::ResourceLimits::height(FUZZ_MAX_SIZE);
50
584
    Magick::ResourceLimits::listLength(16);
51
584
  }
FuzzingInitializer::FuzzingInitializer()
Line
Count
Source
38
292
  {
39
    // Disable SIMD in jpeg turbo.
40
292
    (void) putenv(const_cast<char *>("JSIMD_FORCENONE=1"));
41
42
292
    Magick::InitializeMagick((const char *) NULL);
43
292
    Magick::SecurityPolicy::anonymousCacheMemoryMap();
44
292
    Magick::SecurityPolicy::anonymousSystemMemoryMap();
45
292
    Magick::SecurityPolicy::maxMemoryRequest(128000000);
46
292
    Magick::ResourceLimits::memory(1000000000);
47
292
    Magick::ResourceLimits::map(500000000);
48
292
    Magick::ResourceLimits::width(FUZZ_MAX_SIZE);
49
292
    Magick::ResourceLimits::height(FUZZ_MAX_SIZE);
50
292
    Magick::ResourceLimits::listLength(16);
51
292
  }
FuzzingInitializer::FuzzingInitializer()
Line
Count
Source
38
292
  {
39
    // Disable SIMD in jpeg turbo.
40
292
    (void) putenv(const_cast<char *>("JSIMD_FORCENONE=1"));
41
42
292
    Magick::InitializeMagick((const char *) NULL);
43
292
    Magick::SecurityPolicy::anonymousCacheMemoryMap();
44
292
    Magick::SecurityPolicy::anonymousSystemMemoryMap();
45
292
    Magick::SecurityPolicy::maxMemoryRequest(128000000);
46
292
    Magick::ResourceLimits::memory(1000000000);
47
292
    Magick::ResourceLimits::map(500000000);
48
292
    Magick::ResourceLimits::width(FUZZ_MAX_SIZE);
49
292
    Magick::ResourceLimits::height(FUZZ_MAX_SIZE);
50
292
    Magick::ResourceLimits::listLength(16);
51
292
  }
52
};
53
54
FuzzingInitializer fuzzingInitializer;
55
56
#if defined(BUILD_MAIN)
57
#include "encoder_format.h"
58
59
EncoderFormat encoderFormat;
60
61
#define FUZZ_ENCODER encoderFormat.get()
62
#endif