From 9cc6a9e071a3247fbb05ec7d6dd38463470ef05b Mon Sep 17 00:00:00 2001 From: Rafi Shamim Date: Tue, 10 Jan 2023 18:09:27 +0000 Subject: [PATCH] tree: fix panic when encoding tuple This adds a bounds check to avoid a panic. Release note (bug fix): Fixed a crash that could happen when formatting a tuple with an unknown type. --- pkg/sql/sem/tree/pgwire_encode.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/sql/sem/tree/pgwire_encode.go b/pkg/sql/sem/tree/pgwire_encode.go index 6a043e3767fd..f2e74d350b0c 100644 --- a/pkg/sql/sem/tree/pgwire_encode.go +++ b/pkg/sql/sem/tree/pgwire_encode.go @@ -49,7 +49,10 @@ func (d *DTuple) pgwireFormat(ctx *FmtCtx) { comma := "" for i, v := range d.D { ctx.WriteString(comma) - t := d.ResolvedType().TupleContents()[i] + t := v.ResolvedType() + if tc := d.ResolvedType().TupleContents(); i < len(tc) { + t = tc[i] + } switch dv := UnwrapDOidWrapper(v).(type) { case dNull: case *DString: