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

[Fuzzing] Update the fuzzing suite to native Go-Fuzz #215

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -19,6 +19,10 @@ fmt: ## Run go fmt against code
tests: ## Run all tests and requires a running rabbitmq-server. Use GO_TEST_FLAGS to add extra flags to go test
go test -race -v -tags integration $(GO_TEST_FLAGS)

.PHONY: fuzzing
fuzzing: ## Run fuzzing tests
go test -fuzz=FuzzReadFrame .

.PHONY: tests-docker
tests-docker: rabbitmq-server
RABBITMQ_RABBITMQCTL_PATH="DOCKER:$(CONTAINER_NAME)" go test -race -v -tags integration $(GO_TEST_FLAGS)
Expand Down
23 changes: 0 additions & 23 deletions fuzz.go

This file was deleted.

6 changes: 6 additions & 0 deletions read.go
Expand Up @@ -114,6 +114,12 @@ func readLongstr(r io.Reader) (v string, err error) {
return
}

// LRB TODO obviously this is not realistic
if length > 65536 {
err = ErrMsgSize
return
}

bytes := make([]byte, length)
if _, err = io.ReadFull(r, bytes); err != nil {
return
Expand Down
13 changes: 13 additions & 0 deletions read_test.go
Expand Up @@ -6,6 +6,7 @@
package amqp091

import (
"bytes"
"strings"
"testing"
)
Expand All @@ -29,3 +30,15 @@ func TestGoFuzzCrashers(t *testing.T) {
}
}
}

func FuzzReadFrame(f *testing.F) {

f.Add([]byte("\b000000"))
f.Add([]byte("\x02\x16\x10�[��\t\xbdui�" + "\x10\x01\x00\xff\xbf\xef\xbfサn\x99\x00\x10r"))
f.Add([]byte("\x0300\x00\x00\x00\x040000"))

f.Fuzz(func(t *testing.T, input_data []byte) {
r := reader{bytes.NewReader(input_data)}
_, _ = r.ReadFrame()
})
}
3 changes: 3 additions & 0 deletions types.go
Expand Up @@ -63,6 +63,9 @@ var (

// ErrFieldType is returned when writing a message containing a Go type unsupported by AMQP.
ErrFieldType = &Error{Code: SyntaxError, Reason: "unsupported table field type"}

// ErrMsgSize is returned when the length specifier for a frame or its data exceeds 128 MiB
ErrMsgSize = &Error{Code: FrameError, Reason: "frame or message is too large"}
)

// internal errors used inside the library
Expand Down