Coverage Report

Created: 2023-09-25 07:05

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