From 6a8868207066ce6b45c186516be6b5f2dfeeb96b Mon Sep 17 00:00:00 2001 From: Faizan Qazi Date: Fri, 6 Oct 2023 09:52:55 -0400 Subject: [PATCH] pg_catalog: indoption was not encoded correctly Previously, the indoption field inside pg_index was encoded incorrectly, which could cause problems for binary clients. Specifically, an int8 was being sent across the wire, then int2vectors are supposed to be made of int2. To address this, this patch ensures that an int2 is used and adds assertion inside the conversion code (for int2vector) to avoid future problems. Fixes: #111907 Release note (bug fix): indoption inside pg_index was not properly encoded, causing clients to be unable to decode it as int2vector. --- pkg/sql/pg_catalog.go | 2 +- pkg/sql/sem/tree/datum.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index ad1b9e3c9b0b..99487de51009 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -1879,7 +1879,7 @@ https://www.postgresql.org/docs/9.5/catalog-pg-index.html`, // Also fill in indoption for each column to indicate if the index // is ASC/DESC and if nulls appear first/last. collationOids := tree.NewDArray(types.Oid) - indoption := tree.NewDArray(types.Int) + indoption := tree.NewDArray(types.Int2) colAttNums := make([]descpb.ColumnID, 0, index.NumKeyColumns()) exprs := make([]string, 0, index.NumKeyColumns()) diff --git a/pkg/sql/sem/tree/datum.go b/pkg/sql/sem/tree/datum.go index f4330cfe71dc..5c1f8198c9e0 100644 --- a/pkg/sql/sem/tree/datum.go +++ b/pkg/sql/sem/tree/datum.go @@ -5922,6 +5922,10 @@ func NewDName(d string) Datum { // NewDIntVectorFromDArray is a helper routine to create a new *DArray, // initialized from an existing *DArray, with the special oid for IntVector. func NewDIntVectorFromDArray(d *DArray) Datum { + // Sanity: Validate the type of the array, since it should be int2. + if d.ParamTyp != types.Int2 { + panic(errors.AssertionFailedf("int2vector can only be made from int2 not %v", d.ParamTyp)) + } ret := new(DArray) *ret = *d ret.customOid = oid.T_int2vector