Coverage Report

Created: 2026-12-01 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/glaze/fuzzing/json_jmespath.cpp
Line
Count
Source
1
#include <algorithm>
2
#include <cstddef>
3
#include <cstdint>
4
#include <glaze/glaze.hpp>
5
#include <glaze/json/jmespath.hpp>
6
#include <string>
7
#include <string_view>
8
9
struct Person
10
{
11
   std::string first_name{};
12
   std::string last_name{};
13
   uint16_t age{};
14
};
15
16
namespace
17
{
18
   template <bool null_terminated>
19
   void impl(const std::size_t pathsize, std::string_view all_buffer)
20
15.9k
   {
21
      // make separate allocations to make it easier for address sanitizer to catch
22
      // out of bounds access. also, make the size known up front so the allocation is
23
      // as tight as possible.
24
15.9k
      std::vector<char> path(pathsize + +null_terminated);
25
15.9k
      std::copy(all_buffer.begin(), all_buffer.begin() + pathsize, path.begin());
26
27
15.9k
      std::vector<char> buffer(all_buffer.size() - pathsize + +null_terminated);
28
15.9k
      std::copy(all_buffer.begin() + pathsize, all_buffer.end(), buffer.begin());
29
30
15.9k
      Person child{};
31
15.9k
      static constexpr glz::opts options{.null_terminated = null_terminated};
32
15.9k
      [[maybe_unused]] auto result =
33
15.9k
         glz::read_jmespath<options>(std::string_view(path.data(), path.size() - +null_terminated), child,
34
15.9k
                                     std::string_view(buffer.data(), buffer.size() - +null_terminated));
35
15.9k
   }
json_jmespath.cpp:void (anonymous namespace)::impl<true>(unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >)
Line
Count
Source
20
8.48k
   {
21
      // make separate allocations to make it easier for address sanitizer to catch
22
      // out of bounds access. also, make the size known up front so the allocation is
23
      // as tight as possible.
24
8.48k
      std::vector<char> path(pathsize + +null_terminated);
25
8.48k
      std::copy(all_buffer.begin(), all_buffer.begin() + pathsize, path.begin());
26
27
8.48k
      std::vector<char> buffer(all_buffer.size() - pathsize + +null_terminated);
28
8.48k
      std::copy(all_buffer.begin() + pathsize, all_buffer.end(), buffer.begin());
29
30
8.48k
      Person child{};
31
8.48k
      static constexpr glz::opts options{.null_terminated = null_terminated};
32
8.48k
      [[maybe_unused]] auto result =
33
8.48k
         glz::read_jmespath<options>(std::string_view(path.data(), path.size() - +null_terminated), child,
34
8.48k
                                     std::string_view(buffer.data(), buffer.size() - +null_terminated));
35
8.48k
   }
json_jmespath.cpp:void (anonymous namespace)::impl<false>(unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >)
Line
Count
Source
20
7.48k
   {
21
      // make separate allocations to make it easier for address sanitizer to catch
22
      // out of bounds access. also, make the size known up front so the allocation is
23
      // as tight as possible.
24
7.48k
      std::vector<char> path(pathsize + +null_terminated);
25
7.48k
      std::copy(all_buffer.begin(), all_buffer.begin() + pathsize, path.begin());
26
27
7.48k
      std::vector<char> buffer(all_buffer.size() - pathsize + +null_terminated);
28
7.48k
      std::copy(all_buffer.begin() + pathsize, all_buffer.end(), buffer.begin());
29
30
7.48k
      Person child{};
31
7.48k
      static constexpr glz::opts options{.null_terminated = null_terminated};
32
7.48k
      [[maybe_unused]] auto result =
33
7.48k
         glz::read_jmespath<options>(std::string_view(path.data(), path.size() - +null_terminated), child,
34
7.48k
                                     std::string_view(buffer.data(), buffer.size() - +null_terminated));
35
7.48k
   }
36
}
37
38
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
39
24.1k
{
40
24.1k
   constexpr auto bytes_used_for_nullterm = 1;
41
24.1k
   constexpr auto bytes_used_for_size = 2;
42
24.1k
   if (Size < bytes_used_for_size + bytes_used_for_nullterm) return 0;
43
44
24.1k
   const bool null_terminated = Data[0];
45
24.1k
   Data += bytes_used_for_nullterm;
46
24.1k
   Size -= bytes_used_for_nullterm;
47
48
24.1k
   const auto pathsize = std::min(Size - bytes_used_for_size, size_t{Data[0]} + (Data[1] << 8));
49
24.1k
   Data += bytes_used_for_size;
50
24.1k
   Size -= bytes_used_for_size;
51
52
24.1k
   const std::string_view all_buffer{(const char*)Data, Size};
53
54
24.1k
   if (null_terminated) {
55
12.9k
      impl<true>(pathsize, all_buffer);
56
12.9k
   }
57
11.2k
   else {
58
11.2k
      impl<false>(pathsize, all_buffer);
59
11.2k
   }
60
61
24.1k
   return 0;
62
24.1k
}