http2_frame_decoder_fuzzer.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <stddef.h>
  5. #include <stdint.h>
  6. #include <fuzzer/FuzzedDataProvider.h>
  7. #include <list>
  8. #include <vector>
  9. #include "net/third_party/quiche/src/quiche/http2/decoder/http2_frame_decoder.h"
  10. // Entry point for LibFuzzer.
  11. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  12. FuzzedDataProvider fuzzed_data_provider(data, size);
  13. http2::Http2FrameDecoder decoder(nullptr);
  14. // Store all chunks in a function scope list, as the API requires the caller
  15. // to make sure the fragment chunks data is accessible during the whole
  16. // decoding process. |http2::DecodeBuffer| does not copy the data, it is just
  17. // a wrapper for the chunk provided in its constructor.
  18. std::list<std::vector<char>> all_chunks;
  19. while (fuzzed_data_provider.remaining_bytes() > 0) {
  20. size_t chunk_size = fuzzed_data_provider.ConsumeIntegralInRange(1, 32);
  21. all_chunks.emplace_back(
  22. fuzzed_data_provider.ConsumeBytes<char>(chunk_size));
  23. const auto& chunk = all_chunks.back();
  24. // http2::DecodeBuffer constructor does not accept nullptr buffer.
  25. if (chunk.data() == nullptr)
  26. continue;
  27. http2::DecodeBuffer frame_data(chunk.data(), chunk.size());
  28. decoder.DecodeFrame(&frame_data);
  29. }
  30. return 0;
  31. }