Coverage Report

Created: 2021-09-27 09:58

/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 <cstdint>
7
#include <cstddef>
8
#include <string>
9
10
namespace google {
11
namespace grpc {
12
namespace transcoding {
13
namespace testing {
14
namespace {
15
16
571
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
17
571
  FuzzedDataProvider provider(data, size);
18
19
571
  TestZeroCopyInputStream input_stream;
20
571
  MessageReader reader(&input_stream);
21
22
3.68M
  while (provider.remaining_bytes() > 0) {
23
24
    // Add a few chucks of data to the input stream.
25
4.49M
    for (int i = 0; i < provider.ConsumeIntegralInRange(0, 5); i++) {
26
809k
      input_stream.AddChunk(provider.ConsumeRandomLengthString(100));
27
809k
    }
28
29
    // Run the message reader to get the next message.
30
3.68M
    (void) reader.NextMessageAndGrpcFrame();
31
32
    // Handle end of input or error due to malformed bytes.
33
3.68M
    if (reader.Finished()) {
34
85
      return 0;
35
85
    }
36
3.68M
  }
37
38
486
  return 0;
39
571
}
40
41
}
42
}
43
}
44
}
45
}