Coverage Report

Created: 2023-07-01 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
620
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
17
620
  FuzzedDataProvider provider(data, size);
18
19
620
  TestZeroCopyInputStream input_stream;
20
620
  MessageReader reader(&input_stream);
21
22
1.68M
  while (provider.remaining_bytes() > 0) {
23
    // Add a few chucks of data to the input stream.
24
2.86M
    for (int i = 0; i < provider.ConsumeIntegralInRange(0, 5); i++) {
25
1.17M
      input_stream.AddChunk(provider.ConsumeRandomLengthString(100));
26
1.17M
    }
27
28
    // Run the message reader to get the next message.
29
1.68M
    (void)reader.NextMessageAndGrpcFrame();
30
31
    // Handle end of input or error due to malformed bytes.
32
1.68M
    if (reader.Finished()) {
33
125
      return 0;
34
125
    }
35
1.68M
  }
36
37
495
  return 0;
38
620
}
39
}
40
}
41
}
42
}
43
}