blob: a2bb3a2c2bad9e2fb5aff19c3fff87fc9967b135 [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/testing/fuzzed_data_provider.h"
namespace blink {
FuzzedDataProvider::FuzzedDataProvider(const uint8_t* bytes, size_t num_bytes)
: provider_(bytes, num_bytes) {}
String FuzzedDataProvider::ConsumeRandomLengthString(size_t max_length) {
std::string str = provider_.ConsumeRandomLengthString(max_length);
// FromUTF8 will return a null string if the input data contains invalid UTF-8
// sequences. Fall back to latin1 in those cases.
return String::FromUTF8WithLatin1Fallback(, str.length());
CString FuzzedDataProvider::ConsumeRemainingBytes() {
std::vector<char> bytes = provider_.ConsumeRemainingBytes<char>();
return CString(, bytes.size());
} // namespace blink