Skip to content

Commit

Permalink
Directly test bufbuild/protocompile, instead of going through jhump/p…
Browse files Browse the repository at this point in the history
…rotoreflect/desc/protoparse (#12504)

I've recently merged a long-lived "v2" branch to main in the
`github.com/jhump/protoreflect` repo. The v2 of that repo does _not_
include a protoparse package, since that has been effectively replaced
by `github.com/bufbuild/protocompile`. (Since v1.15 of protoreflect, the
protoparse package is just API veneer on top of protocompile.)

After I did that merge of v2 to main, the fuzzer for the project began
to fail since the packages are no longer present:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=71629
So this updates the fuzzer configuration to directly test the underlying
protocompile module.

There was also a fuzz tester for the
`github.com/jhump/protoreflect/dynamic` package, but it was not actually
enabled. (It was disabled in #6369 but neither the PR description nor
comment threads describe why this test was problematic 🤷.) Anyhow, that
package has also been removed for v2, effectively replaced by
`google.golang.org/protobuf/types/dynamicpb`. So this PR deletes it
completely from the oss-fuzz repo.
  • Loading branch information
jhump authored Sep 18, 2024
1 parent afc8ca9 commit 62f0f44
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
################################################################################

FROM gcr.io/oss-fuzz-base/base-builder-go
RUN git clone --depth 1 https://github.com/jhump/protoreflect
RUN git clone --depth 1 https://github.com/bufbuild/protocompile

COPY fuzz_protoparse.go $SRC/protoreflect/desc/protoparse/
COPY fuzz_dynamic.go $SRC/protoreflect/proto_decoder/
COPY fuzz_protocompile.go $SRC/protocompile

COPY build.sh $SRC/
WORKDIR $SRC/protoreflect
WORKDIR $SRC/protocompile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
#
################################################################################

compile_go_fuzzer github.com/jhump/protoreflect/desc/protoparse FuzzProtoParse fuzz_protoparse
# compile_go_fuzzer github.com/jhump/protoreflect/proto_decoder Fuzz fuzz_dynamic
compile_go_fuzzer github.com/bufbuild/protocompile FuzzProtoCompile fuzz_protocompile

37 changes: 37 additions & 0 deletions projects/protocompile/fuzz_protocompile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2024 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.

package protocompile

import (
"bytes"
"context"
"io"
)

func FuzzProtoCompile(data []byte) int {
compiler := &Compiler{
Resolver: &SourceResolver{
Accessor: func(_ string) (closer io.ReadCloser, e error) {
return io.NopCloser(bytes.NewReader(data)), nil
},
},
}

_, err := compiler.Compile(context.Background(), "test.proto")
if err != nil {
return 0
}
return 1
}
10 changes: 10 additions & 0 deletions projects/protocompile/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
homepage: "https://github.com/bufbuild/protocompile"
primary_contact: "jhumphries@buf.build"
auto_ccs:
- "oss-fuzz-reports@buf.build"
language: go
fuzzing_engines:
- libfuzzer
sanitizers:
- address
main_repo: 'https://github.com/bufbuild/protocompile'
33 changes: 0 additions & 33 deletions projects/protoreflect/fuzz_dynamic.go

This file was deleted.

21 changes: 0 additions & 21 deletions projects/protoreflect/fuzz_protoparse.go

This file was deleted.

10 changes: 0 additions & 10 deletions projects/protoreflect/project.yaml

This file was deleted.

0 comments on commit 62f0f44

Please sign in to comment.