Skip to content

Commit

Permalink
stats, encoding: improve UUID-decoding error
Browse files Browse the repository at this point in the history
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
  • Loading branch information
michae2 committed Nov 22, 2024
1 parent 4cb6ede commit 330810d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/sql/stats/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package stats

import (
"context"
"encoding/hex"
"fmt"
"math"
"sort"
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/util/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 330810d

Please sign in to comment.