Skip to content

fix: the overflow guard overflowed, and armv7 shipped from an unbuilt matrix - #354

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/32bit-overflow-guard-198
Aug 5, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/32bit-overflow-guard-198

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #198.

The one-line defect

safeIntToUint32 bounded its conversion with if i > 0xFFFFFFFF. int is 32 bits wide on 32-bit platforms and that constant is not, so the guard against overflow overflowed:

$ CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build ./internal/fuse/
internal/fuse/filesystem.go:37:9: 0xFFFFFFFF (untyped int constant 4294967295) overflows int

It is now uint64(i) > math.MaxUint32, which holds the value on every word width. The negative check stays first and has to: uint64(-1) is 2^64-1, which would clamp to MaxUint32 rather than to zero.

That was the only error on the target — with it fixed the whole tree cross-builds for linux/arm and linux/386.

Per the issue, safeInt64ToUint64 directly above it was audited too. It has no equivalent defect: int64 and uint64 are both 64 bits on every platform Go targets, so it has no upper bound to test and no constant to overflow. That is now stated in its doc comment, because "why does one of these check two things and the other check one" is a fair question to have answered in place.

Why it reached a release, which is the part worth reviewing

linux/armv7 appeared in release.yml's matrix and in nothing else. Every cross-build cell in ci.yml was 64-bit, and no test running on a 64-bit host can see this class of defect — i > 0xFFFFFFFF compiles and behaves correctly on amd64 and arm64. So the break first appeared when a tag was pushed, at which point the cheapest response was to delete the cell. In v0.10.1 that is what happened, and the platform went with it.

Measured on this branch, with the original comparison restored:

result
go build ./... (this host, arm64) exit 0
go vet ./... (this host) exit 0
go test -race ./internal/fuse/ exit 0
GOOS=linux GOARCH=arm GOARM=7 go build ./internal/fuse/ exit 1
GOOS=linux GOARCH=386 go build ./internal/fuse/ exit 1
GOOS=linux GOARCH=arm GOARM=7 go build ./cmd/objectfs exit 1

Everything a 64-bit host runs is green. That is where the gate has to live.

The coupling

Same shape as #240's build-tags matrix, and the same reasoning — an unbuilt target is not merely untested:

  • ci.yml's cross-build matrix gains linux/arm (GOARM=7) and linux/386.
  • TestEveryReleasePlatformIsCompiledInCI fails if release.yml publishes a platform that matrix does not build.
  • The relation is deliberately release ⊆ ci, not equality: linux/386 is compiled and not published, as a second 32-bit word-width canary. An extra CI cell costs a minute; an unbuilt release cell ships a broken platform.
  • TestThirtyTwoBitIsStillInTheCrossBuildMatrix asserts at least one cell has a 32-bit int, stated by word width rather than by naming arm — so dropping one 32-bit platform while keeping another stays green, and going all-64-bit again does not.
  • linux/armv7 is back in release.yml. Per the issue: a platform that builds but is never shipped gets no runtime exposure either.

Each cross-build cell now also runs go vet ./internal/... ./pkg/... ./cmd/.... go build does not compile _test.go files, so a width bug in a test — int(math.MaxUint32) is the same error in the same shape, and the new test had to route around it — would still pass a green build cell. Scoped away from sdks/c, which is cgo and cannot be vetted under CGO_ENABLED=0 for any target; #200 covers that surface.

GOARM is set explicitly in both workflows rather than left to the toolchain default. armv6 and armv7 binaries are not interchangeable and the artifact is named linux-armv7, so the flag should say 7 rather than trust that it will keep meaning 7.

Tests

internal/fuse/width_guard_test.go — the table the issue asked for (math.MaxUint32, MaxUint32+1 skipped on 32-bit, -1, 0), plus MinInt, MaxInt, and the branch-order case. Table-driven, t.Parallel().

The header states plainly what these tests cannot do: no test on a 64-bit host catches the actual regression, because the defect is a compile error. The gate for that is the cross-build cell. What the tests do cover is the behavior, which had never been asserted at all — the clamps, the boundaries, and the branch ordering.

One wrinkle worth flagging: the table's boundary values are built through a uint64 variable rather than written as int(math.MaxUint32), because that constant conversion is itself a compile error on 32-bit — a test for a 32-bit compile bug that cannot be compiled on 32-bit would be no test. Confirmed: GOOS=linux GOARCH=arm go vet ./internal/fuse/ and GOARCH=386 both pass, which type-checks the test file for those targets.

internal/config/release_platforms_test.go — the two coupling tests, in the package where build_tags_test.go already does this and repoRoot lives.

Verification

Mutations, eight. Four behavioral, four structural:

mutation result
restore i > 0xFFFFFFFF 64-bit build/vet/test all pass; arm, 386 and cmd/objectfs-for-arm fail
swap the two branches TestSafeIntToUint32 fails
delete the negative check TestSafeIntToUint32 fails
delete safeInt64ToUint64's negative check TestSafeInt64ToUint64 fails
remove the linux/arm cell from ci.yml coupling test fails, naming linux/arm
remove both 32-bit cells both coupling tests fail
add freebsd/amd64 to release.yml coupling test fails, naming it
rename the cross-build job coupling test fatals rather than passing vacuously

That last one is the failure mode a test that parses a workflow is most likely to have, so it is checked explicitly.

Not claimed: > versus >= on the boundary is an equivalent mutant — clamping MaxUint32 to MaxUint32 returns the same value either way, so no test can distinguish them.

Everything else:

  • go test -race -timeout 20m ./... — green, exit 0.
  • go vet -tags=<tag> ./... clean for all six build tags.
  • Six targets cross-build ./... and ./cmd/objectfs, and cross-vet ./internal/... ./pkg/... ./cmd/...: linux/{amd64,arm64,arm,386}, darwin/{amd64,arm64}.
  • linux/arm GOARM=7 produces ELF 32-bit LSB executable, ARM, EABI5.
  • golangci-lint run --new-from-merge-base=origin/main — 0 issues. gofmt clean.
  • Both workflows parse; matrix contents and per-step env verified after editing.
  • markdownlint at baseline: CHANGELOG 361, DEVELOPMENT 16.

Two things found along the way

DEVELOPMENT.md's cross-build section listed three of the five shipped platforms plus a GOOS=windows build that has never produced a binary — internal/fuse is linux || darwin and platform_unsupported.go fails deliberately. Corrected to what release.yml publishes, with the 386 canary noted and a sentence on why Windows is absent.

A dead -X main.Version injection, three copies. cmd/objectfs/main.go declares the version in a const block and the linker cannot rewrite a constant:

$ go build -ldflags="-X main.Version=FAKE-VERSION" -o /tmp/probe ./cmd/objectfs
$ /tmp/probe --version
objectfs version 0.11.0

release.yml:127 already documents this and v0.10.3 removed it there and from the Dockerfile. The copy in DEVELOPMENT.md:444 is fixed here since I was editing the file; Makefile:11 and OBJECTFS.md:613 are filed as #353 rather than fixed in a PR about a different thing — the Makefile one affects six targets and deserves its own review of whether commit and build time should be injected for real.

… matrix

`safeIntToUint32` bounded an `int` against `0xFFFFFFFF`, a constant that does
not fit a 32-bit `int`. `internal/fuse` therefore did not compile for any
32-bit target — a compile error, not a wrong answer:

  internal/fuse/filesystem.go:37:9: 0xFFFFFFFF (untyped int constant
  4294967295) overflows int

Compared as uint64 now. The negative check stays first, and has to: uint64(-1)
is 2^64-1 and would clamp to MaxUint32 rather than zero. `safeInt64ToUint64`
beside it was audited and has no equivalent defect — both types are 64 bits on
every target, so it has no upper bound to test.

The more interesting half is why it reached a release. linux/armv7 was in
release.yml's matrix and in nothing else; every ci.yml cross-build cell was
64-bit, and no test on a 64-bit host can see this class of defect. So the break
surfaced only on a pushed tag, where the cheapest response was to delete the
cell — which is what v0.10.1 did, taking the platform with it.

So the durable fix is a coupling: cross-build gains linux/arm and linux/386
cells, and TestEveryReleasePlatformIsCompiledInCI fails if release.yml ships a
platform that matrix does not build. Release ⊆ ci, not equality — 386 is a
second word-width canary and is not published.
TestThirtyTwoBitIsStillInTheCrossBuildMatrix asserts the word width rather than
a platform name. Each cell also vets, because `go build` skips _test.go and a
width bug in a test is the same error in the same shape.

Verified: restoring the original comparison passes build, vet and the full
suite here while failing arm, 386 and ./cmd/objectfs for arm. Three behavioral
mutations fail the new table tests; four workflow mutations fail the coupling
tests, including renaming the job, since a parser that reads nothing would pass
vacuously.

Closes #198. Refs #353 (two surviving copies of a dead -X main.Version).
@scttfrdmn scttfrdmn added type: bug Something isn't working as expected priority: medium Important but not urgent area: build Build system, compilation, packaging area: fuse FUSE layer and filesystem interface area: ci-cd CI workflows, gates, and release automation effort: xs Extra small effort - <2 hours labels Aug 4, 2026
@scttfrdmn
scttfrdmn merged commit 90e951a into main Aug 5, 2026
39 checks passed
@scttfrdmn
scttfrdmn deleted the fix/32bit-overflow-guard-198 branch August 5, 2026 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build Build system, compilation, packaging area: ci-cd CI workflows, gates, and release automation area: fuse FUSE layer and filesystem interface effort: xs Extra small effort - <2 hours priority: medium Important but not urgent type: bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fuse: safeIntToUint32 does not compile on 32-bit — the overflow guard overflows

1 participant