From 660a14af3e9928142b02e58e533403e5a963ab6e 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 a5e4f718fb4d..2586008963b0 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" @@ -135,6 +136,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 71716f1c01a1..668998ca7211 100644 --- a/pkg/util/encoding/encoding.go +++ b/pkg/util/encoding/encoding.go @@ -3162,6 +3162,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