Skip to content

Commit

Permalink
chore: fix some bad conversions (#9703)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
codyoss committed Apr 4, 2024
1 parent 81830e6 commit 9221c7f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion auth/httptransport/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions pubsublite/pscompat/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion spanner/spansql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 9221c7f

Please sign in to comment.