Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:

jobs:
build:
name: Build (Bundled ${{ matrix.bundled_protobuf }}, ${{ matrix.build_type }})
runs-on: ${{ matrix.os }}

strategy:
Expand All @@ -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.
Expand All @@ -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 }}

Expand Down
2 changes: 1 addition & 1 deletion examples/libfuzzer/libfuzzer_bin_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion examples/libfuzzer/libfuzzer_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
12 changes: 10 additions & 2 deletions src/field_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/mutator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/mutator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down