Coverage Report

Created: 2024-02-25 06:31

/proc/self/cwd/test/message_reader_fuzz_test.cc
Line
Count
Source
1
#include "grpc_transcoding/message_reader.h"
2
3
#include "test_common.h"
4
5
#include <fuzzer/FuzzedDataProvider.h>
6
#include <cstddef>
7
#include <cstdint>
8
#include <string>
9
10
namespace google {
11
namespace grpc {
12
namespace transcoding {
13
namespace testing {
14
namespace {
15
16
615
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
17
615
  FuzzedDataProvider provider(data, size);
18
19
615
  TestZeroCopyInputStream input_stream;
20
615
  MessageReader reader(&input_stream);
21
22
2.62M
  while (provider.remaining_bytes() > 0) {
23
    // Add a few chucks of data to the input stream.
24
3.78M
    for (int i = 0; i < provider.ConsumeIntegralInRange(0, 5); i++) {
25
1.16M
      input_stream.AddChunk(provider.ConsumeRandomLengthString(100));
26
1.16M
    }
27
28
    // Run the message reader to get the next message.
29
2.62M
    (void)reader.NextMessageAndGrpcFrame();
30
31
    // Handle end of input or error due to malformed bytes.
32
2.62M
    if (reader.Finished()) {
33
132
      return 0;
34
132
    }
35
2.62M
  }
36
37
483
  return 0;
38
615
}
39
}
40
}
41
}
42
}
43
}