ppd_line_reader_fuzzer.cc 984 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2019 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 "chromeos/printing/ppd_line_reader.h"
  5. #include <memory>
  6. #include <string>
  7. #include <fuzzer/FuzzedDataProvider.h>
  8. namespace {
  9. constexpr int kUpperMaxLineLengthBound = 1024;
  10. } // namespace
  11. namespace chromeos {
  12. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  13. FuzzedDataProvider data_provider(data, size);
  14. const size_t line_length =
  15. data_provider.ConsumeIntegralInRange<size_t>(0, kUpperMaxLineLengthBound);
  16. const std::string contents = data_provider.ConsumeRemainingBytesAsString();
  17. std::unique_ptr<PpdLineReader> ppd_line_reader =
  18. PpdLineReader::Create(contents, line_length);
  19. std::string line;
  20. while (ppd_line_reader->NextLine(&line)) {
  21. // Call NextLine() until we hit the end of the file or an error.
  22. }
  23. return 0;
  24. }
  25. } // namespace chromeos