Initial fuzz testing and fix
Initial fuzz testing of pgproto3 found a panic
This commit is contained in:
@@ -223,7 +223,13 @@ func (f *Frontend) Receive() (BackendMessage, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
f.msgType = header[0]
|
f.msgType = header[0]
|
||||||
f.bodyLen = int(binary.BigEndian.Uint32(header[1:])) - 4
|
|
||||||
|
msgLength := int(binary.BigEndian.Uint32(header[1:]))
|
||||||
|
if msgLength < 4 {
|
||||||
|
return nil, fmt.Errorf("invalid message length: %d", msgLength)
|
||||||
|
}
|
||||||
|
|
||||||
|
f.bodyLen = msgLength - 4
|
||||||
f.partialMsg = true
|
f.partialMsg = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package pgproto3_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5/pgproto3"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func FuzzFrontend(f *testing.F) {
|
||||||
|
testcases := [][]byte{
|
||||||
|
{'Z', 0, 0, 0, 5},
|
||||||
|
}
|
||||||
|
for _, tc := range testcases {
|
||||||
|
f.Add(tc)
|
||||||
|
}
|
||||||
|
f.Fuzz(func(t *testing.T, encodedMsg []byte) {
|
||||||
|
r := &bytes.Buffer{}
|
||||||
|
w := &bytes.Buffer{}
|
||||||
|
fe := pgproto3.NewFrontend(r, w)
|
||||||
|
|
||||||
|
_, err := r.Write(encodedMsg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Not checking anything other than no panic.
|
||||||
|
fe.Receive()
|
||||||
|
})
|
||||||
|
}
|
||||||
pgproto3/testdata/fuzz/FuzzFrontend/65d91093341a68b16f04605e392b0501847a9b35d3857e67872046dbdc04913e
Vendored
+2
@@ -0,0 +1,2 @@
|
|||||||
|
go test fuzz v1
|
||||||
|
[]byte("0\x00\x00\x00\x02")
|
||||||
Reference in New Issue
Block a user