1 // Copyright 2017 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <string> 6 #include <string_view> 7 8 #include "base/base64.h" 9 #include "base/check_op.h" 10 11 // Encode some random data, and then decode it. LLVMFuzzerTestOneInput(const uint8_t * data_ptr,size_t size)12extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data_ptr, size_t size) { 13 // SAFETY: libfuzzer provides a valid pointer and size pair. 14 auto data = UNSAFE_BUFFERS(base::span(data_ptr, size)); 15 std::string_view data_string = base::as_string_view(data); 16 17 const std::string encode_output = base::Base64Encode(data); 18 std::string decode_output; 19 CHECK(base::Base64Decode(encode_output, &decode_output)); 20 CHECK_EQ(data_string, decode_output); 21 22 // Also run the std::string_view variant and check that it gives the same 23 // results. 24 CHECK_EQ(encode_output, base::Base64Encode(data_string)); 25 26 return 0; 27 } 28