From 330810d567fe361a5fd86febf54f79bb089e997e Mon Sep 17 00:00:00 2001 From: Michael Erickson Date: Fri, 22 Nov 2024 18:23:43 +0000 Subject: [PATCH] stats, encoding: improve UUID-decoding error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a length check to `DecodeUUIDValue` and a more informative error wrapping to `DecodeUpperBound`, which will hopefully help us track down the cause of #128876. The wrapped error message looks like: ``` decoding histogram version 3 type uuid value ‹666f6f›: invalid uuid length of 2 ``` Informs: #128876 Epic: None Release note: None --- pkg/sql/stats/histogram.go | 7 +++++++ pkg/util/encoding/encoding.go | 3 +++ 2 files changed, 10 insertions(+) diff --git a/pkg/sql/stats/histogram.go b/pkg/sql/stats/histogram.go index 543ee70c24c0..ca87af77236d 100644 --- a/pkg/sql/stats/histogram.go +++ b/pkg/sql/stats/histogram.go @@ -7,6 +7,7 @@ package stats import ( "context" + "encoding/hex" "fmt" "math" "sort" @@ -114,6 +115,12 @@ func DecodeUpperBound( } else { datum, _, err = keyside.Decode(a, typ, upperBound, encoding.Ascending) } + if err != nil { + err = errors.Wrapf( + err, "decoding histogram version %d type %v value %v", + int(version), typ.Family().Name(), hex.EncodeToString(upperBound), + ) + } return datum, err } diff --git a/pkg/util/encoding/encoding.go b/pkg/util/encoding/encoding.go index 862ec9041918..1e3357b96d76 100644 --- a/pkg/util/encoding/encoding.go +++ b/pkg/util/encoding/encoding.go @@ -3152,6 +3152,9 @@ func DecodeUUIDValue(b []byte) (remaining []byte, u uuid.UUID, err error) { // DecodeUntaggedUUIDValue decodes a value encoded by EncodeUntaggedUUIDValue. func DecodeUntaggedUUIDValue(b []byte) (remaining []byte, u uuid.UUID, err error) { + if len(b) < uuidValueEncodedLength { + return b, uuid.UUID{}, errors.Errorf("invalid uuid length of %d", len(b)) + } u, err = uuid.FromBytes(b[:uuidValueEncodedLength]) if err != nil { return b, uuid.UUID{}, err