🐛 bug: Fix math.MaxUint32 overflow in etag middleware on 32-bit platforms#4135
🐛 bug: Fix math.MaxUint32 overflow in etag middleware on 32-bit platforms#4135ReneWerner87 merged 2 commits intomainfrom
Conversation
Co-authored-by: ReneWerner87 <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4135 +/- ##
=======================================
Coverage 91.10% 91.10%
=======================================
Files 119 119
Lines 11385 11385
=======================================
Hits 10372 10372
Misses 642 642
Partials 371 371
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@copilot we probably have to cast MaxUint32 by doing; uint32(math.MaxUint32) |
Using The Happy to change the approach if you have a different preference in mind though! |
|
@copilot Please review the codebase to determine if this fix needs to be applied elsewhere. |
I searched the entire codebase for
I also verified the full build compiles cleanly on 32-bit: |
There was a problem hiding this comment.
Pull request overview
Fixes a 32-bit build failure in the etag middleware caused by comparing len(body) (typed int) against math.MaxUint32 (untyped constant too large for 32-bit int). This keeps etag (and transitively compress) compiling and working on 32-bit GOARCH targets.
Changes:
- Compare
uint64(len(body))/uint64(bodyLength)tomath.MaxUint32inGenerateand theNewmiddleware handler to avoid 32-bit constant overflow.
On 32-bit platforms,
intis 32-bit and cannot represent the untyped constantmath.MaxUint32(4,294,967,295). The comparisonslen(body) > math.MaxUint32in theetagmiddleware caused a compile-time error on 32-bit targets, breaking any app using thecompressmiddleware (which depends onetag).Changes introduced
middleware/etag/etag.go: Castlen(body)touint64before comparing withmath.MaxUint32in bothGenerateand theNewhandler.uint64holds the constant on all platforms; on 32-bit,len()can never exceedmath.MaxInt32 < math.MaxUint32so the check is always false (correct behavior preserved).etagmiddleware (GOARCH=386,GOARCH=arm, etc.).Type of change
Checklist
/docs/directory for Fiber's documentation.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
exampleretry.com/tmp/go-build1732996263/b307/client.test /tmp/go-build1732996263/b307/client.test -test.paniconexit0 -test.v=test2json -test.timeout=10m0s -test.count=1 -test.shuffle=on 0.1-go1.25.0.linux-amd64/src/runcrypto/sha256 ux-amd64/pkg/tool/linux_amd64/vet -d main l/linux_amd64/co-unreachable=false ux-amd64/pkg/too/tmp/go-build1732996263/b102/vet.cfg -V=f�� aiJC5TRFccldbcSaLaNp/aiJC5TRFccl-p l/linux_amd64/compile ux-amd64/pkg/tool/linux_amd64/vet -c=4 -nolocalimports -importcfg ux-amd64/pkg/too-buildtags(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.