diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index d3aff61..905ff0b 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -12,6 +12,7 @@ on: jobs: build: + name: Build (Bundled ${{ matrix.bundled_protobuf }}, ${{ matrix.build_type }}) runs-on: ${{ matrix.os }} strategy: @@ -28,16 +29,26 @@ jobs: os: [ubuntu-24.04] build_type: [Release, Debug] c_compiler: [clang] - include: - - os: ubuntu-24.04 - c_compiler: clang - cpp_compiler: clang++ + cpp_compiler: [clang++] + bundled_protobuf: ['ON', 'OFF'] steps: - uses: actions/checkout@v3 - name: Install Deps - run: sudo apt install -y liblzma-dev ninja-build + run: | + ubuntu_packages=( + liblzma-dev + ninja-build + ) + if [[ ${{ matrix.bundled_protobuf }} == OFF ]]; then + ubuntu_packages+=( + libprotobuf-dev + protobuf-compiler + ) + fi + set -x + sudo apt install -y "${ubuntu_packages[@]}" - name: Set reusable strings # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. @@ -56,7 +67,7 @@ jobs: -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_C_FLAGS='-Werror' -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -DLIB_PROTO_MUTATOR_DOWNLOAD_PROTOBUF=ON + -DLIB_PROTO_MUTATOR_DOWNLOAD_PROTOBUF=${{ matrix.bundled_protobuf }} -GNinja -S ${{ github.workspace }} diff --git a/examples/libfuzzer/libfuzzer_bin_example.cc b/examples/libfuzzer/libfuzzer_bin_example.cc index 62bb45a..cd31aad 100644 --- a/examples/libfuzzer/libfuzzer_bin_example.cc +++ b/examples/libfuzzer/libfuzzer_bin_example.cc @@ -55,7 +55,7 @@ DEFINE_BINARY_PROTO_FUZZER(const libfuzzer_example::Msg& message) { !std::isnan(message.optional_float()) && std::fabs(message.optional_float()) > 1000 && message.any().UnpackTo(&file) && !file.name().empty()) { - std::cerr << protobuf_mutator::protobuf::ShortFormat(message) << "\n"; + std::cerr << message.DebugString() << "\n"; abort(); } } diff --git a/examples/libfuzzer/libfuzzer_example.cc b/examples/libfuzzer/libfuzzer_example.cc index a7b9ba5..2e6e887 100644 --- a/examples/libfuzzer/libfuzzer_example.cc +++ b/examples/libfuzzer/libfuzzer_example.cc @@ -55,7 +55,7 @@ DEFINE_PROTO_FUZZER(const libfuzzer_example::Msg& message) { !std::isnan(message.optional_float()) && std::fabs(message.optional_float()) > 1000 && message.any().UnpackTo(&file) && !file.name().empty()) { - std::cerr << protobuf_mutator::protobuf::ShortFormat(message) << "\n"; + std::cerr << message.DebugString() << "\n"; abort(); } } diff --git a/src/field_instance.h b/src/field_instance.h index 823d19b..e05d8e9 100644 --- a/src/field_instance.h +++ b/src/field_instance.h @@ -190,14 +190,22 @@ class ConstFieldInstance { return descriptor_->message_type(); } - bool EnforceUtf8() const { return descriptor_->requires_utf8_validation(); } + bool EnforceUtf8() const { +#if PROTOBUF_VERSION >= 4022000 // v3(!).22.0 (commit d85c9944c55fb38f4eae149979a0f680ea125ecb) for requires_utf8_validation + return descriptor_->requires_utf8_validation(); +#else + return descriptor_->type() == protobuf::FieldDescriptor::TYPE_STRING && + descriptor()->file()->syntax() == + protobuf::FileDescriptor::SYNTAX_PROTO3; +#endif + } const protobuf::FieldDescriptor* descriptor() const { return descriptor_; } std::string DebugString() const { std::string s = descriptor_->DebugString(); if (is_repeated()) s += "[" + std::to_string(index_) + "]"; - return s + " of\n" + protobuf::ShortFormat(*message_); + return s + " of\n" + message_->DebugString(); } protected: diff --git a/src/mutator.cc b/src/mutator.cc index 191204e..ee2f213 100644 --- a/src/mutator.cc +++ b/src/mutator.cc @@ -801,7 +801,7 @@ std::string Mutator::MutateUtf8String(const std::string& value, bool Mutator::IsInitialized(const Message& message) const { if (!keep_initialized_ || message.IsInitialized()) return true; - std::cerr << "Uninitialized: " << protobuf::ShortFormat(message) << "\n"; + std::cerr << "Uninitialized: " << message.DebugString() << "\n"; return false; } diff --git a/src/mutator_test.cc b/src/mutator_test.cc index 8cd5013..e534e1e 100644 --- a/src/mutator_test.cc +++ b/src/mutator_test.cc @@ -410,8 +410,8 @@ bool Mutate(const protobuf::Message& from, const protobuf::Message& to, } ADD_FAILURE() << "Failed to get from:\n" - << protobuf::ShortFormat(from) << "\nto:\n" - << protobuf::ShortFormat(to); + << from.DebugString() << "\nto:\n" + << to.DebugString(); return false; }