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