Coverage Report

Created: 2026-06-30 07:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/imagemagick/oss-fuzz/encoder_utils.cc
Line
Count
Source
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/license/
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
static int fuzzEncoderWithStringFileName(const std::string encoder,
18
  const uint8_t *data,size_t size,bool (*validate)(const std::string &) = NULL)
19
29.0k
{
20
29.0k
  std::string
21
29.0k
    fileName;
22
23
29.0k
  if (IsInvalidSize(size))
24
72
    return(0);
25
28.9k
  fileName=std::string(reinterpret_cast<const char*>(data), size);
26
  // Can be used to deny specific file names
27
28.9k
  if ((validate != NULL) && (validate(fileName) == false))
28
40
    return(0);
29
28.9k
  try
30
28.9k
  {
31
28.9k
    Magick::Image
32
28.9k
      image;
33
34
28.9k
    image.read(encoder + ":" + fileName);
35
28.9k
  }
36
#if defined(BUILD_MAIN)
37
  catch (Magick::Exception &e)
38
  {
39
    std::cout << "Exception when reading: " << e.what() << std::endl;
40
  }
41
#else
42
28.9k
  catch (Magick::Exception)
43
28.9k
  {
44
18.7k
  }
45
28.9k
#endif
46
28.9k
  return(0);
47
28.9k
}
encoder_plasma_fuzzer.cc:fuzzEncoderWithStringFileName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned char const*, unsigned long, bool (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&))
Line
Count
Source
19
4.57k
{
20
4.57k
  std::string
21
4.57k
    fileName;
22
23
4.57k
  if (IsInvalidSize(size))
24
13
    return(0);
25
4.56k
  fileName=std::string(reinterpret_cast<const char*>(data), size);
26
  // Can be used to deny specific file names
27
4.56k
  if ((validate != NULL) && (validate(fileName) == false))
28
0
    return(0);
29
4.56k
  try
30
4.56k
  {
31
4.56k
    Magick::Image
32
4.56k
      image;
33
34
4.56k
    image.read(encoder + ":" + fileName);
35
4.56k
  }
36
#if defined(BUILD_MAIN)
37
  catch (Magick::Exception &e)
38
  {
39
    std::cout << "Exception when reading: " << e.what() << std::endl;
40
  }
41
#else
42
4.56k
  catch (Magick::Exception)
43
4.56k
  {
44
2.21k
  }
45
4.56k
#endif
46
4.56k
  return(0);
47
4.56k
}
encoder_gradient_fuzzer.cc:fuzzEncoderWithStringFileName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned char const*, unsigned long, bool (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&))
Line
Count
Source
19
3.74k
{
20
3.74k
  std::string
21
3.74k
    fileName;
22
23
3.74k
  if (IsInvalidSize(size))
24
10
    return(0);
25
3.73k
  fileName=std::string(reinterpret_cast<const char*>(data), size);
26
  // Can be used to deny specific file names
27
3.73k
  if ((validate != NULL) && (validate(fileName) == false))
28
0
    return(0);
29
3.73k
  try
30
3.73k
  {
31
3.73k
    Magick::Image
32
3.73k
      image;
33
34
3.73k
    image.read(encoder + ":" + fileName);
35
3.73k
  }
36
#if defined(BUILD_MAIN)
37
  catch (Magick::Exception &e)
38
  {
39
    std::cout << "Exception when reading: " << e.what() << std::endl;
40
  }
41
#else
42
3.73k
  catch (Magick::Exception)
43
3.73k
  {
44
1.59k
  }
45
3.73k
#endif
46
3.73k
  return(0);
47
3.73k
}
encoder_xc_fuzzer.cc:fuzzEncoderWithStringFileName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned char const*, unsigned long, bool (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&))
Line
Count
Source
19
3.53k
{
20
3.53k
  std::string
21
3.53k
    fileName;
22
23
3.53k
  if (IsInvalidSize(size))
24
11
    return(0);
25
3.52k
  fileName=std::string(reinterpret_cast<const char*>(data), size);
26
  // Can be used to deny specific file names
27
3.52k
  if ((validate != NULL) && (validate(fileName) == false))
28
0
    return(0);
29
3.52k
  try
30
3.52k
  {
31
3.52k
    Magick::Image
32
3.52k
      image;
33
34
3.52k
    image.read(encoder + ":" + fileName);
35
3.52k
  }
36
#if defined(BUILD_MAIN)
37
  catch (Magick::Exception &e)
38
  {
39
    std::cout << "Exception when reading: " << e.what() << std::endl;
40
  }
41
#else
42
3.52k
  catch (Magick::Exception)
43
3.52k
  {
44
1.61k
  }
45
3.52k
#endif
46
3.52k
  return(0);
47
3.52k
}
encoder_pattern_fuzzer.cc:fuzzEncoderWithStringFileName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned char const*, unsigned long, bool (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&))
Line
Count
Source
19
3.78k
{
20
3.78k
  std::string
21
3.78k
    fileName;
22
23
3.78k
  if (IsInvalidSize(size))
24
13
    return(0);
25
3.76k
  fileName=std::string(reinterpret_cast<const char*>(data), size);
26
  // Can be used to deny specific file names
27
3.76k
  if ((validate != NULL) && (validate(fileName) == false))
28
0
    return(0);
29
3.76k
  try
30
3.76k
  {
31
3.76k
    Magick::Image
32
3.76k
      image;
33
34
3.76k
    image.read(encoder + ":" + fileName);
35
3.76k
  }
36
#if defined(BUILD_MAIN)
37
  catch (Magick::Exception &e)
38
  {
39
    std::cout << "Exception when reading: " << e.what() << std::endl;
40
  }
41
#else
42
3.76k
  catch (Magick::Exception)
43
3.76k
  {
44
2.08k
  }
45
3.76k
#endif
46
3.76k
  return(0);
47
3.76k
}
encoder_label_fuzzer.cc:fuzzEncoderWithStringFileName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned char const*, unsigned long, bool (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&))
Line
Count
Source
19
9.68k
{
20
9.68k
  std::string
21
9.68k
    fileName;
22
23
9.68k
  if (IsInvalidSize(size))
24
12
    return(0);
25
9.67k
  fileName=std::string(reinterpret_cast<const char*>(data), size);
26
  // Can be used to deny specific file names
27
9.67k
  if ((validate != NULL) && (validate(fileName) == false))
28
40
    return(0);
29
9.63k
  try
30
9.63k
  {
31
9.63k
    Magick::Image
32
9.63k
      image;
33
34
9.63k
    image.read(encoder + ":" + fileName);
35
9.63k
  }
36
#if defined(BUILD_MAIN)
37
  catch (Magick::Exception &e)
38
  {
39
    std::cout << "Exception when reading: " << e.what() << std::endl;
40
  }
41
#else
42
9.63k
  catch (Magick::Exception)
43
9.63k
  {
44
9.63k
  }
45
9.63k
#endif
46
9.63k
  return(0);
47
9.63k
}
encoder_radial-gradient_fuzzer.cc:fuzzEncoderWithStringFileName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned char const*, unsigned long, bool (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&))
Line
Count
Source
19
3.72k
{
20
3.72k
  std::string
21
3.72k
    fileName;
22
23
3.72k
  if (IsInvalidSize(size))
24
13
    return(0);
25
3.71k
  fileName=std::string(reinterpret_cast<const char*>(data), size);
26
  // Can be used to deny specific file names
27
3.71k
  if ((validate != NULL) && (validate(fileName) == false))
28
0
    return(0);
29
3.71k
  try
30
3.71k
  {
31
3.71k
    Magick::Image
32
3.71k
      image;
33
34
3.71k
    image.read(encoder + ":" + fileName);
35
3.71k
  }
36
#if defined(BUILD_MAIN)
37
  catch (Magick::Exception &e)
38
  {
39
    std::cout << "Exception when reading: " << e.what() << std::endl;
40
  }
41
#else
42
3.71k
  catch (Magick::Exception)
43
3.71k
  {
44
1.59k
  }
45
3.71k
#endif
46
3.71k
  return(0);
47
3.71k
}