MCPcopy
hub / github.com/jackc/pgx / TestBindDecodeNegativeParameterLength

Function TestBindDecodeNegativeParameterLength

pgproto3/bind_test.go:11–34  ·  view source on GitHub ↗

https://github.com/jackc/pgx/issues/2519

(t *testing.T)

Source from the content-addressed store, hash-verified

9
10// https://github.com/jackc/pgx/issues/2519
11func TestBindDecodeNegativeParameterLength(t *testing.T) {
12 t.Parallel()
13
14 // Craft a Bind message with a negative parameter length that is not -1.
15 // This should return an error, not panic.
16 //
17 // Message layout:
18 // - destination portal: "" (1 byte null terminator)
19 // - prepared statement: "" (1 byte null terminator)
20 // - parameter format code count: 0 (2 bytes)
21 // - parameter count: 1 (2 bytes)
22 // - parameter 0 length: -2 (4 bytes, 0xFFFFFFFE)
23 src := []byte{
24 0, // destination portal null terminator
25 0, // prepared statement null terminator
26 0, 0, // parameter format code count = 0
27 0, 1, // parameter count = 1
28 0xFF, 0xFF, 0xFF, 0xFE, // parameter length = -2
29 }
30
31 var bind pgproto3.Bind
32 err := bind.Decode(src)
33 require.Error(t, err, "Bind.Decode should reject negative parameter length other than -1")
34}
35
36func TestBindBiggerThanMaxMessageBodyLen(t *testing.T) {
37 t.Parallel()

Callers

nothing calls this directly

Calls 2

DecodeMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected