Skip to content

[protobuf-c] Restore missing fuzzer implementation #13071

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions projects/protobuf-c/Dockerfile
Original file line number Diff line number Diff line change
@@ -28,5 +28,4 @@ RUN apt-get update && apt-get install -y \

RUN git clone --depth 1 https://github.com/protobuf-c/protobuf-c.git -b next
RUN git clone --depth 1 https://github.com/guidovranken/fuzzing-headers.git
RUN git clone --depth 1 https://github.com/guidovranken/protobuf-c-fuzzers.git
COPY build.sh $SRC/
COPY build.sh fuzzer.cpp $SRC/
4 changes: 2 additions & 2 deletions projects/protobuf-c/build.sh
Original file line number Diff line number Diff line change
@@ -47,8 +47,8 @@ make install
cd $SRC/fuzzing-headers/
./install.sh

cd $SRC/protobuf-c-fuzzers/
cp $SRC/protobuf-c/t/test-full.proto $SRC/protobuf-c-fuzzers/
cd $SRC
cp $SRC/protobuf-c/t/test-full.proto $SRC/
export PATH=$PATH:$SRC/protobuf-c/protoc-c
protoc --c_out=. -I. -I/usr/local/include test-full.proto

38 changes: 38 additions & 0 deletions projects/protobuf-c/fuzzer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Copyright 2025 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/* Special thanks to Guido Vranken <guidovranken@gmail.com> */

#include <assert.h>
#include <stdlib.h>
#include <fuzzing/memory.hpp>
#include "test-full.pb-c.h"

#define X(OBJ, PREFIX) \
{ \
OBJ* msg = PREFIX##__unpack(NULL, size, data); \
if ( msg != NULL ) { \
const size_t len = PREFIX##__get_packed_size(msg); \
uint8_t* copy = (uint8_t*)malloc(len); \
PREFIX##__pack(msg, copy); \
fuzzing::memory::memory_test(copy, len); \
free(copy); \
} \
PREFIX##__free_unpacked(msg, NULL); \
}

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
X(Foo__TestMessSubMess, foo__test_mess_sub_mess);
X(Foo__TestFieldFlags, foo__test_field_flags);
X(Foo__TestMessageCheck, foo__test_message_check);
return 0;
}