mirror of
https://github.com/jackc/pgx.git
synced 2025-04-27 13:14:32 +00:00
The PostgreSQL server will reject messages greater than ~1 GB anyway. However, worse than that is that a message that is larger than 4 GB could wrap the 32-bit integer message size and be interpreted by the server as multiple messages. This could allow a malicious client to inject arbitrary protocol messages. https://github.com/jackc/pgx/security/advisories/GHSA-mrww-27vc-gghv
21 lines
545 B
Go
21 lines
545 B
Go
package pgproto3_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5/pgproto3"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestQueryBiggerThanMaxMessageBodyLen(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Maximum allowed size. 4 bytes for size and 1 byte for 0 terminated string.
|
|
_, err := (&pgproto3.Query{String: string(make([]byte, pgproto3.MaxMessageBodyLen-5))}).Encode(nil)
|
|
require.NoError(t, err)
|
|
|
|
// 1 byte too big
|
|
_, err = (&pgproto3.Query{String: string(make([]byte, pgproto3.MaxMessageBodyLen-4))}).Encode(nil)
|
|
require.Error(t, err)
|
|
}
|