Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated rollback of commit ed1dddd0e1fad41d33572d437dce773175454909. #1240

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions common/blob_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <iterator>
#include <memory>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -186,6 +187,10 @@ class DefaultBlobFileReader : public BlobFileReader {
riegeli_reader_.Reset(riegeli::kClosed);
#endif // CENTIPEDE_DISABLE_RIEGELI

// Because we fall back to a legacy reader, we can't distinguish between
// an empty blob file and a file that is not a blob file. Once this behavior
// changes (e.g., we get rid of the legacy reader), consider b/349115475 and
// track down places that would benefit from this distinction.
legacy_reader_ = std::make_unique<SimpleBlobFileReader>();
if (absl::Status s = legacy_reader_->Open(path); !s.ok()) {
legacy_reader_ = nullptr;
Expand Down Expand Up @@ -285,9 +290,13 @@ class RiegeliWriter : public BlobFileWriter {
}

absl::Status Write(ByteSpan blob) override {
std::string_view blob_view = AsStringView(blob);
const auto now = absl::Now();
if (!PreWriteFlush(blob.size())) return writer_.status();
if (!writer_.WriteRecord(AsStringView(blob))) return writer_.status();
if (!writer_.WriteRecord(
absl::string_view{blob_view.data(), blob_view.size()})) {
return writer_.status();
}
if (!PostWriteFlush(blob.size())) return writer_.status();
write_duration_ += absl::Now() - now;
if (written_blobs_ + buffered_blobs_ % 10000 == 0)
Expand Down Expand Up @@ -436,11 +445,13 @@ ByteArray PackBytesForAppendFile(ByteSpan blob) {
size_t size = blob.size();
uint8_t size_bytes[sizeof(size)];
std::memcpy(size_bytes, &size, sizeof(size));
res.insert(res.end(), &kPackBegMagic[0], &kPackBegMagic[kMagicLen]);
res.insert(res.end(), std::begin(kPackBegMagic),
std::begin(kPackBegMagic) + kMagicLen);
res.insert(res.end(), hash.begin(), hash.end());
res.insert(res.end(), &size_bytes[0], &size_bytes[sizeof(size_bytes)]);
res.insert(res.end(), std::begin(size_bytes), std::end(size_bytes));
res.insert(res.end(), blob.begin(), blob.end());
res.insert(res.end(), &kPackEndMagic[0], &kPackEndMagic[kMagicLen]);
res.insert(res.end(), std::begin(kPackEndMagic),
std::begin(kPackEndMagic) + kMagicLen);
return res;
}

Expand Down
3 changes: 3 additions & 0 deletions common/remote_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ void RemoteFileGetContents(std::string_view path, std::string &contents);
// Returns true if `path` exists.
bool RemotePathExists(std::string_view path);

// Returns true if `path` is a directory.
bool RemotePathIsDirectory(std::string_view path);

// Returns the size of the file at `path` in bytes. The file must exist.
int64_t RemoteFileGetSize(std::string_view path);

Expand Down
8 changes: 8 additions & 0 deletions common/remote_file_oss.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ bool RemotePathExists(std::string_view path) {
LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}

bool RemotePathIsDirectory(std::string_view path) {
LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}

std::vector<std::string> RemoteListFiles(std::string_view path,
bool recursively) {
LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
Expand All @@ -151,6 +155,10 @@ bool RemotePathExists(std::string_view path) {
return std::filesystem::exists(path);
}

bool RemotePathIsDirectory(std::string_view path) {
return std::filesystem::is_directory(path);
}

std::vector<std::string> RemoteListFiles(std::string_view path,
bool recursively) {
if (!std::filesystem::exists(path)) return {};
Expand Down
6 changes: 4 additions & 2 deletions e2e_tests/functional_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,10 @@ void ExpectCorpusInputMessageInLogs(absl::string_view logs, int num_inputs) {
HasSubstr(absl::StrFormat("%d inputs to rerun", num_inputs)))
<< logs;
#else
EXPECT_THAT(logs, HasSubstr(absl::StrFormat(
"Parsed %d inputs and ignored 0 inputs", num_inputs)))
EXPECT_THAT(logs,
HasSubstr(absl::StrFormat(
"In total, loaded %d inputs and ignored 0 invalid inputs",
num_inputs)))
<< logs;
#endif
}
Expand Down
17 changes: 15 additions & 2 deletions fuzztest/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ cc_library(
"fuzztest_macros.h",
],
deps = [
":io",
":registration",
":registry",
"@com_google_absl//absl/log:check",
Expand Down Expand Up @@ -453,6 +454,7 @@ cc_library(
":configuration",
":corpus_database",
":flag_name",
":io",
":registry",
":runtime",
"@com_google_absl//absl/strings",
Expand All @@ -478,9 +480,15 @@ cc_library(
hdrs = ["internal/io.h"],
deps = [
":logging",
"@com_google_absl//absl/functional:function_ref",
"@com_google_absl//absl/hash",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/types:span",
"@com_google_fuzztest//common:blob_file",
"@com_google_fuzztest//common:defs",
"@com_google_fuzztest//common:remote_file",
] + select({
"//conditions:default": [],
}),
Expand All @@ -492,7 +500,11 @@ cc_test(
deps = [
":fuzztest_core",
":io",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_fuzztest//common:blob_file",
"@com_google_fuzztest//common:defs",
"@com_google_googletest//:gtest_main",
],
)
Expand Down Expand Up @@ -583,19 +595,20 @@ cc_library(
":flag_name",
":io",
":logging",
":meta",
":printer",
":registration",
":seed_seq",
":serialization",
":type_support",
":status",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/functional:bind_front",
"@com_google_absl//absl/functional:function_ref",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/random",
"@com_google_absl//absl/random:bit_gen_ref",
"@com_google_absl//absl/random:distributions",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/time",
Expand Down
18 changes: 16 additions & 2 deletions fuzztest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ fuzztest_cc_library(
SRCS
"fuzztest_macros.cc"
DEPS
fuzztest::io
fuzztest::registration
fuzztest::registry
)
Expand Down Expand Up @@ -376,6 +377,7 @@ fuzztest_cc_library(
DEPS
fuzztest::configuration
fuzztest::corpus_database
fuzztest::io
fuzztest::registry
fuzztest::runtime
absl::strings
Expand All @@ -402,9 +404,16 @@ fuzztest_cc_library(
SRCS
"internal/io.cc"
DEPS
fuzztest::blob_file
fuzztest::defs
fuzztest::logging
fuzztest::remote_file
absl::function_ref
absl::hash
absl::status
absl::str_format
absl::string_view
absl::span
)

fuzztest_cc_test(
Expand All @@ -413,8 +422,12 @@ fuzztest_cc_test(
SRCS
"internal/io_test.cc"
DEPS
fuzztest::blob_file
fuzztest::defs
fuzztest::fuzztest_core
fuzztest::io
absl::check
absl::status
absl::strings
GTest::gmock_main
)
Expand Down Expand Up @@ -512,19 +525,20 @@ fuzztest_cc_library(
fuzztest::fixture_driver
fuzztest::io
fuzztest::logging
fuzztest::meta
fuzztest::printer
fuzztest::registration
fuzztest::seed_seq
fuzztest::serialization
fuzztest::type_support
fuzztest::status
absl::any_invocable
absl::bind_front
absl::function_ref
absl::check
absl::random_random
absl::random_bit_gen_ref
absl::random_distributions
absl::status
absl::statusor
absl::strings
absl::str_format
absl::time
Expand Down
3 changes: 2 additions & 1 deletion fuzztest/fuzztest_macros.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <cerrno>
#include <cstring>
#include <filesystem>
#include <filesystem> // NOLINT
#include <fstream>
#include <sstream>
#include <string>
Expand All @@ -17,6 +17,7 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "./fuzztest/internal/io.h"

namespace fuzztest {

Expand Down
23 changes: 12 additions & 11 deletions fuzztest/internal/centipede_adaptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ class CentipedeAdaptorRunnerCallbacks : public centipede::RunnerCallbacks {
}

bool Execute(centipede::ByteSpan input) override {
if (auto parsed_input =
fuzzer_impl_.TryParse({(char*)input.data(), input.size()})) {
auto parsed_input =
fuzzer_impl_.TryParse({(char*)input.data(), input.size()});
if (parsed_input.ok()) {
fuzzer_impl_.RunOneInput({*std::move(parsed_input)});
return true;
}
Expand All @@ -183,13 +184,12 @@ class CentipedeAdaptorRunnerCallbacks : public centipede::RunnerCallbacks {
std::vector<GenericDomainCorpusType> seeds =
fuzzer_impl_.fixture_driver_->GetSeeds();
CorpusDatabase corpus_database(configuration_);
for (const std::string& corpus_file :
corpus_database.GetCoverageInputsIfAny(
fuzzer_impl_.test_.full_name())) {
auto corpus_value = fuzzer_impl_.GetCorpusValueFromFile(corpus_file);
if (!corpus_value) continue;
seeds.push_back(*corpus_value);
}
fuzzer_impl_.ForEachInput(
corpus_database.GetCoverageInputsIfAny(fuzzer_impl_.test_.full_name()),
[&](absl::string_view /*file_path*/, std::optional<int> /*blob_idx*/,
FuzzTestFuzzerImpl::Input input) {
seeds.push_back(std::move(input.args));
});
constexpr int kInitialValuesInSeeds = 32;
for (int i = 0; i < kInitialValuesInSeeds; ++i) {
seeds.push_back(fuzzer_impl_.params_domain_.Init(prng_));
Expand Down Expand Up @@ -226,9 +226,10 @@ class CentipedeAdaptorRunnerCallbacks : public centipede::RunnerCallbacks {
inputs[absl::Uniform<size_t>(prng_, 0, inputs.size())].data;
auto parsed_origin =
fuzzer_impl_.TryParse({(const char*)origin.data(), origin.size()});
if (!parsed_origin)
if (!parsed_origin.ok()) {
parsed_origin = fuzzer_impl_.params_domain_.Init(prng_);
auto mutant = FuzzTestFuzzerImpl::Input{*parsed_origin};
}
auto mutant = FuzzTestFuzzerImpl::Input{*std::move(parsed_origin)};
fuzzer_impl_.MutateValue(mutant, prng_);
mutant_data =
fuzzer_impl_.params_domain_.SerializeCorpus(mutant.args).ToString();
Expand Down
1 change: 1 addition & 0 deletions fuzztest/internal/googletest_adaptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "./fuzztest/internal/configuration.h"
#include "./fuzztest/internal/corpus_database.h"
#include "./fuzztest/internal/flag_name.h"
#include "./fuzztest/internal/io.h"
#include "./fuzztest/internal/registry.h"
#include "./fuzztest/internal/runtime.h"

Expand Down
Loading
Loading