fix: prevent integer overflow on 32-bit architectures in helper.size - #2097
Open
josejuanmontiel wants to merge 1 commit into
Open
josejuanmontiel wants to merge 1 commit into
josejuanmontiel wants to merge 1 commit into
Conversation
In Go, the size of the `int` type is architecture-dependent (32 bits on 32-bit systems). The `ExaByte`, `PetaByte`, and `TeraByte` constants defined in `cmd/helper/size.go` exceed the maximum capacity of a 32-bit integer (2,147,483,647). This caused an integer overflow during compilation on 32-bit targets like `armv6` or `armv7` (e.g., Raspberry Pi Zero): "cannot use ExaByte (untyped int constant 1152921504606846976) as int value in map literal (overflows)" This commit changes the type of `unitMap` keys and the return type of `getUnit` from `int` to `int64` to ensure safe compilation across all architectures without altering functionality.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a compilation issue that prevents
immudbfrom being built on 32-bit architectures (such aslinux/arm/v6orlinux/arm/v7used in IoT devices like the Raspberry Pi Zero).The Issue
In
cmd/helper/size.go,unitMapandgetUnit()were using the standardinttype. In Go, theinttype is architecture-dependent (32 bits on 32-bit operating systems).Since constants like
ExaByte(1,152,921,504,606,846,976) heavily exceedmath.MaxInt32, the Go compiler catches an overflow and throws a fatal error during the build process: