base64_encode_fuzzer.cc 977 B

123456789101112131415161718192021222324252627
  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 <string>
  5. #include "base/base64.h"
  6. #include "base/check_op.h"
  7. #include "base/strings/string_piece.h"
  8. // Encode some random data, and then decode it.
  9. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  10. base::span<const uint8_t> data_span(data, size);
  11. base::StringPiece data_piece(reinterpret_cast<const char*>(data), size);
  12. const std::string encode_output = base::Base64Encode(data_span);
  13. std::string decode_output;
  14. CHECK(base::Base64Decode(encode_output, &decode_output));
  15. CHECK_EQ(data_piece, decode_output);
  16. // Also run the StringPiece variant and check that it gives the same results.
  17. std::string string_piece_encode_output;
  18. base::Base64Encode(data_piece, &string_piece_encode_output);
  19. CHECK_EQ(encode_output, string_piece_encode_output);
  20. return 0;
  21. }