bug: chunkedReader.Read read up to math.MaxInt on 32bit platforms #137

Merged
nemith merged 1 commit from brb/push-pkyokursztlx into main 2026-01-09 00:51:19 +00:00
nemith commented 2026-01-09 00:39:18 +00:00 (Migrated from github.com)

The chunkedWriter correctly works with the max int size on 32bit platforms but the read side was still assuming math.MaxUint32. Since len(p) is weirdly signed this doesn't work so cap it at Math.MaxInt the same way we do for the writer.

I really wish Go used usize for things like this cause this is just a pain in the ass.

The chunkedWriter correctly works with the max `int` size on 32bit platforms but the read side was still assuming math.MaxUint32. Since len(p) is weirdly signed this doesn't work so cap it at Math.MaxInt the same way we do for the writer. I really wish Go used usize for things like this cause this is just a pain in the ass.
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2026-01-09 00:41:31 +00:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Pull request overview

This PR fixes a bug in the chunkedReader implementation where it was using math.MaxUint32 instead of math.MaxInt to cap buffer sizes on 32-bit platforms. Since Go slice lengths are signed integers (type int), this caused issues on 32-bit systems where math.MaxUint32 exceeds the maximum value of int.

Key changes:

  • Moved maxChunkSize constant from chunkedWriter.Write method to package-level scope for reuse
  • Updated chunkedReader.Read to use maxChunkSize instead of math.MaxUint32, ensuring consistency with the writer and proper handling on 32-bit platforms

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

## Pull request overview This PR fixes a bug in the chunkedReader implementation where it was using `math.MaxUint32` instead of `math.MaxInt` to cap buffer sizes on 32-bit platforms. Since Go slice lengths are signed integers (type `int`), this caused issues on 32-bit systems where `math.MaxUint32` exceeds the maximum value of `int`. Key changes: - Moved `maxChunkSize` constant from `chunkedWriter.Write` method to package-level scope for reuse - Updated `chunkedReader.Read` to use `maxChunkSize` instead of `math.MaxUint32`, ensuring consistency with the writer and proper handling on 32-bit platforms --- 💡 <a href="/nemith/netconf/new/main/.github/instructions?filename=*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
@ -139,6 +139,12 @@ func (f *Framer) MsgWriter() (io.WriteCloser, error) {
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-01-09 00:41:30 +00:00

The comment mentions "MaxInt32" but should refer to "MaxInt" for accuracy. On 32-bit systems, math.MaxInt equals math.MaxInt32, but on 64-bit systems, math.MaxInt equals math.MaxInt64. The comment should be updated to reflect that slice lengths are limited to math.MaxInt (not specifically MaxInt32).

// RFC 6242 allows up to MaxUint32 (4294967295), but slice lengths are
// limited to math.MaxInt. We use the minimum of both to ensure
// compatibility across all architectures.
The comment mentions "MaxInt32" but should refer to "MaxInt" for accuracy. On 32-bit systems, math.MaxInt equals math.MaxInt32, but on 64-bit systems, math.MaxInt equals math.MaxInt64. The comment should be updated to reflect that slice lengths are limited to math.MaxInt (not specifically MaxInt32). ```suggestion // RFC 6242 allows up to MaxUint32 (4294967295), but slice lengths are // limited to math.MaxInt. We use the minimum of both to ensure // compatibility across all architectures. ```
Sign in to join this conversation.
No description provided.