From 9221c7fa12cef9d5fb7ddc92f41f1d6204971c7b Mon Sep 17 00:00:00 2001 From: Cody Oss <6331106+codyoss@users.noreply.github.com> Date: Thu, 4 Apr 2024 10:46:16 -0500 Subject: [PATCH] chore: fix some bad conversions (#9703) Be more defensive with type conversions. BEGIN_NESTED_COMMIT fix(pubsublite): fix int conversion END_NESTED_COMMIT BEGIN_NESTED_COMMIT fix(spanner): fix uint8 conversion END_NESTED_COMMIT BEGIN_NESTED_COMMIT fix(auth): fix uint32 conversion END_NESTED_COMMIT Fixes: #9704 --- auth/httptransport/trace.go | 2 +- pubsublite/pscompat/message.go | 5 ++--- spanner/spansql/parser.go | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/auth/httptransport/trace.go b/auth/httptransport/trace.go index e996bb5e7ab9..467c477c04df 100644 --- a/auth/httptransport/trace.go +++ b/auth/httptransport/trace.go @@ -77,7 +77,7 @@ func (f *httpFormat) SpanContextFromRequest(req *http.Request) (sc trace.SpanCon if !strings.HasPrefix(h, "o=") { return sc, true } - o, err := strconv.ParseUint(h[2:], 10, 64) + o, err := strconv.ParseUint(h[2:], 10, 32) if err != nil { return trace.SpanContext{}, false } diff --git a/pubsublite/pscompat/message.go b/pubsublite/pscompat/message.go index 02dd092b4cbc..9c4fb03fe281 100644 --- a/pubsublite/pscompat/message.go +++ b/pubsublite/pscompat/message.go @@ -162,11 +162,10 @@ func ParseMessageMetadata(id string) (*MessageMetadata, error) { if len(parts) != 2 { return nil, fmt.Errorf("pubsublite: invalid encoded message metadata %q", id) } - - partition, pErr := strconv.ParseInt(parts[0], 10, 64) + partition, pErr := strconv.Atoi(parts[0]) offset, oErr := strconv.ParseInt(parts[1], 10, 64) if pErr != nil || oErr != nil { return nil, fmt.Errorf("pubsublite: invalid encoded message metadata %q", id) } - return &MessageMetadata{Partition: int(partition), Offset: offset}, nil + return &MessageMetadata{Partition: partition, Offset: offset}, nil } diff --git a/spanner/spansql/parser.go b/spanner/spansql/parser.go index 8686e9f03359..d7b7e4e810fa 100644 --- a/spanner/spansql/parser.go +++ b/spanner/spansql/parser.go @@ -607,7 +607,7 @@ func (p *parser) consumeStringContent(delim string, raw, unicode bool, name stri if !(i+1 < len(p.s) && isHexDigit(p.s[i]) && isHexDigit(p.s[i+1])) { return "", p.errorf("illegal escape sequence: hex escape sequence must be followed by 2 hex digits") } - c, err := strconv.ParseUint(p.s[i:i+2], 16, 64) + c, err := strconv.ParseUint(p.s[i:i+2], 16, 8) if err != nil { return "", p.errorf("illegal escape sequence: invalid hex digits: %q: %v", p.s[i:i+2], err) }