Skip to content

Fix bounds check on envelope for 32-bit archs#887

Merged
emcfarlane merged 6 commits intomainfrom
ed/fixBoundCheck32Bit
Oct 7, 2025
Merged

Fix bounds check on envelope for 32-bit archs#887
emcfarlane merged 6 commits intomainfrom
ed/fixBoundCheck32Bit

Conversation

@emcfarlane
Copy link
Contributor

Fix bounds check on construction of payload envelopes for 32-bit archs.

Fixes #886

Signed-off-by: Edward McFarlane <emcfarlane@buf.build>
Signed-off-by: Edward McFarlane <emcfarlane@buf.build>
Signed-off-by: Edward McFarlane <emcfarlane@buf.build>
envelope.go Outdated
Comment on lines +378 to +384
sizeUint64 := uint64(size)
if size < 0 || sizeUint64 > math.MaxUint32 {
return [5]byte{}, fmt.Errorf("connect.makeEnvelopePrefix: size %d out of bounds", size)
}
prefix := [5]byte{}
prefix[0] = flags
binary.BigEndian.PutUint32(prefix[1:5], uint32(size))
binary.BigEndian.PutUint32(prefix[1:5], uint32(sizeUint64))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really even need the extra var? Also, why not convert to int64 instead of uint64?

Suggested change
sizeUint64 := uint64(size)
if size < 0 || sizeUint64 > math.MaxUint32 {
return [5]byte{}, fmt.Errorf("connect.makeEnvelopePrefix: size %d out of bounds", size)
}
prefix := [5]byte{}
prefix[0] = flags
binary.BigEndian.PutUint32(prefix[1:5], uint32(size))
binary.BigEndian.PutUint32(prefix[1:5], uint32(sizeUint64))
if size < 0 || int64(size) > math.MaxUint32 {
return [5]byte{}, fmt.Errorf("connect.makeEnvelopePrefix: size %d out of bounds", size)
}
prefix := [5]byte{}
prefix[0] = flags
binary.BigEndian.PutUint32(prefix[1:5], uint32(size))

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, casting from int (potentially int32 or int64 depending on arch) to uint64 looks odd even though it should not introduce any issues as negative numbers aren't allowed anyways and if size was negative the cast value is larger than MaxUint32. And we also don't need the extra var here as you suggested but that's also just a minor optimization. I'm fine with keeping it like this as the functionality should now be correct but I do prefer your change suggestion for consistency.

Copy link
Contributor Author

@emcfarlane emcfarlane Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra var is to guide the linter that the cast is safe. Otherwise we need an annotation or .golangci.lint exception. Cast to uint64 as that seemed the more natural thing to compare to math.MaxUint32.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know the linter actually complains in that case, nevermind then. 👍

Copy link
Member

@jhump jhump left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good, but I think would have expected something ever so slightly different.

@MDr164
Copy link

MDr164 commented Sep 29, 2025

The solution suggested in #888 looks a bit cleaner to me as it makes it more obvious that MaxInt could be smaller than MaxUint for certain systems but either one works.

Signed-off-by: Edward McFarlane <emcfarlane@buf.build>
Signed-off-by: Edward McFarlane <emcfarlane@buf.build>
Copy link

@MDr164 MDr164 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a somewhat related note: Would it make sense to run the tests that are currently run in CI for 32bit as well? I think the GH Actions Linux ARM runners support 32bit binaries as well (the Windows variant dropped support for 32bit iirc). Or the regular runners could at least build-test the examples, for that you can use 64bit as well of course.

@emcfarlane
Copy link
Contributor Author

@MDr164 GitHub doesn't supply hosted runners on 32Bit archs. We could cross build as a check. I looked for support for a linter in golangci to no avail. We are also planning to do releases which would catch this build as we would need to cross build to all supported targets.

@emcfarlane emcfarlane merged commit af35892 into main Oct 7, 2025
9 checks passed
@emcfarlane emcfarlane deleted the ed/fixBoundCheck32Bit branch October 7, 2025 15:08
project-mirrors-bot-tu bot pushed a commit to project-mirrors/forgejo-runner that referenced this pull request Oct 11, 2025
This PR contains the following updates:

| Package | Change | Age | Confidence |
|---|---|---|---|
| [connectrpc.com/connect](https://github.com/connectrpc/connect-go) | `v1.18.1` -> `v1.19.1` | [![age](https://developer.mend.io/api/mc/badges/age/go/connectrpc.com%2fconnect/v1.19.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/connectrpc.com%2fconnect/v1.18.1/v1.19.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>connectrpc/connect-go (connectrpc.com/connect)</summary>

### [`v1.19.1`](https://github.com/connectrpc/connect-go/releases/tag/v1.19.1)

[Compare Source](connectrpc/connect-go@v1.19.0...v1.19.1)

<!-- Release notes generated using configuration in .github/release.yml at main -->

#### What's Changed

##### Bugfixes

- Fix bounds check on envelope for 32-bit archs by [@&#8203;emcfarlane](https://github.com/emcfarlane) in [#&#8203;887](connectrpc/connect-go#887)
- Fix CallInfo header/trailer propagation on error responses by [@&#8203;emcfarlane](https://github.com/emcfarlane) in [#&#8203;892](connectrpc/connect-go#892)

**Full Changelog**: <connectrpc/connect-go@v1.19.0...v1.19.1>

### [`v1.19.0`](https://github.com/connectrpc/connect-go/releases/tag/v1.19.0)

[Compare Source](connectrpc/connect-go@v1.18.1...v1.19.0)

This release introduces the highly requested "simple" flag for code generation, making Connect significantly more ergonomic for everyday RPC development.

The new simple flag in protoc-gen-connect-go generates cleaner, more intuitive client and handler interfaces that eliminate request/response wrappers for most use cases. This addresses community feedback about verbosity and provides a more straightforward API. When enabled, metadata (headers/trailers) can be passed through context instead of explicit wrapper objects, optimizing for the common case where developers don't need direct access to HTTP headers.

#### What's Changed

##### Enhancements

- Add simple flag for more ergonomic generated code by [@&#8203;bufdev](https://github.com/bufdev) and [@&#8203;smaye81](https://github.com/smaye81) in [#&#8203;851](connectrpc/connect-go#851)
- Update Go to v1.24 and document http.Protocol use removing the dependency on `golang.org/x/net/http2` by [@&#8203;maxbrunet](https://github.com/maxbrunet) in [#&#8203;873](connectrpc/connect-go#873), [#&#8203;877](connectrpc/connect-go#877)
- Add support for Edition 2024 by [@&#8203;emcfarlane](https://github.com/emcfarlane) in [#&#8203;878](connectrpc/connect-go#878)

##### Bugfixes

- Include valid spec and headers when calling recover handler for streaming RPCs by [@&#8203;jhump](https://github.com/jhump) in [#&#8203;817](connectrpc/connect-go#817)

##### Other changes

- Go version support updated to latest two instead of three by [@&#8203;jhump](https://github.com/jhump) in [#&#8203;837](connectrpc/connect-go#837)
- CI testing improvements by [@&#8203;pkwarren](https://github.com/pkwarren) and [@&#8203;jhump](https://github.com/jhump) in [#&#8203;838](connectrpc/connect-go#838), [#&#8203;839](connectrpc/connect-go#839)
- Code quality improvements by [@&#8203;mattrobenolt](https://github.com/mattrobenolt) and [@&#8203;bufdev](https://github.com/bufdev) in [#&#8203;841](connectrpc/connect-go#841), [#&#8203;867](connectrpc/connect-go#867)
- Documentation improvements by [@&#8203;adlion](https://github.com/adlion) and [@&#8203;stefanvanburen](https://github.com/stefanvanburen) in [#&#8203;821](connectrpc/connect-go#821),
  [#&#8203;880](connectrpc/connect-go#880)

#### New Contributors

- [@&#8203;adlion](https://github.com/adlion) made their first contribution in [#&#8203;821](connectrpc/connect-go#821)
- [@&#8203;maxbrunet](https://github.com/maxbrunet) made their first contribution in [#&#8203;873](connectrpc/connect-go#873)
- [@&#8203;stefanvanburen](https://github.com/stefanvanburen) made their first contribution in [#&#8203;880](connectrpc/connect-go#880)

**Full Changelog**: <connectrpc/connect-go@v1.18.1...v1.19.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC), Automerge - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMzUuNSIsInVwZGF0ZWRJblZlciI6IjQxLjEzNS41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJLaW5kL0RlcGVuZGVuY3lVcGRhdGUiLCJydW4tZW5kLXRvLWVuZC10ZXN0cyJdfQ==-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1078
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
Co-authored-by: Renovate Bot <bot@kriese.eu>
Co-committed-by: Renovate Bot <bot@kriese.eu>
suzuki-shunsuke added a commit to suzuki-shunsuke/mcp-grafana that referenced this pull request Oct 11, 2025
GoReleaser failed at v0.7.3.

https://github.com/grafana/mcp-grafana/releases/tag/v0.7.3
https://github.com/grafana/mcp-grafana/actions/runs/18408789518/job/52455289488

```
  ⨯ release failed after 6m38s
    error=
    │ build failed: exit status 1: # connectrpc.com/connect
Error:     │ ../../../go/pkg/mod/connectrpc.com/connect@v1.19.0/envelope.go:378:24: math.MaxUint32 (untyped int constant 4294967295) overflows int
    target=linux_386_sse2
Error: The process '/opt/hostedtoolcache/goreleaser-action/2.12.5/x64/goreleaser' failed with exit code 1
```

This commit updates connect-go to the latest version to resolve the problem.

connectrpc/connect-go#887
https://github.com/connectrpc/connect-go/releases/tag/v1.19.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

connect-go 1.19.0 fails to build on 32bit ARM

4 participants