Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: int overflow for 32 bit machines #2135

Merged
merged 1 commit into from
Jul 20, 2023

Conversation

rootulp
Copy link
Collaborator

@rootulp rootulp commented Jul 19, 2023

Closes #2129

#2121 didn't actually fix the issue because the expression

NanosecondsPerYear = int64(NanosecondsPerSecond * SecondsPerYear)

was multiplying two ints together prior to the cast to int64. Since the product of those two ints overflows an int32, the value would overflow prior to the cast.

The fix proposed in this PR converts SecondsPerYear to an int64. Now the expression multiplies an int and int64 so the product is an int64 which won't overflow.

Testing

I added this to the Makefile

## build-arm: Build the celestia-appd binary into the ./build directory. Target the linux OS and ARM (32-bit) architecture.
build-arm: mod
	@cd ./cmd/celestia-appd
	@mkdir -p build/
	@GOOS=linux GOARCH=arm go build $(BUILD_FLAGS) -o build/ ./cmd/celestia-appd
	@go mod tidy -compat=1.20
.PHONY: build-arm

Before

$ make build-arm
--> Updating go.mod
# github.com/celestiaorg/celestia-app/x/mint/types
x/mint/types/constants.go:15:29: NanosecondsPerSecond * SecondsPerYear (constant 31556952000000000 of type int) overflows int
make: *** [build-arm] Error 1

After

$ make build-arm
--> Updating go.mod

@rootulp rootulp self-assigned this Jul 19, 2023
@MSevey MSevey requested a review from a team July 19, 2023 17:31
@rootulp rootulp enabled auto-merge (squash) July 19, 2023 18:37
@rootulp rootulp merged commit 9278736 into celestiaorg:main Jul 20, 2023
19 checks passed
@rootulp rootulp deleted the rp/fix-int-overflow branch July 20, 2023 13:38
rootulp added a commit to rootulp/celestia-app that referenced this pull request Jul 20, 2023
Closes celestiaorg#2129

celestiaorg#2121 didn't actually
fix the issue because the expression

```go
NanosecondsPerYear = int64(NanosecondsPerSecond * SecondsPerYear)
```
was multiplying two `int`s together prior to the cast to `int64`. Since
the product of those two `int`s overflows an `int32`, the value would
overflow prior to the cast.

The fix proposed in this PR converts SecondsPerYear to an `int64`. Now
the expression multiplies an `int` and `int64` so the product is an
`int64` which won't overflow.

## Testing

I added this to the Makefile

```go
## build-arm: Build the celestia-appd binary into the ./build directory. Target the linux OS and ARM (32-bit) architecture.
build-arm: mod
	@cd ./cmd/celestia-appd
	@mkdir -p build/
	@Goos=linux GOARCH=arm go build $(BUILD_FLAGS) -o build/ ./cmd/celestia-appd
	@go mod tidy -compat=1.20
.PHONY: build-arm
```

Before

```shell
$ make build-arm
--> Updating go.mod
# github.com/celestiaorg/celestia-app/x/mint/types
x/mint/types/constants.go:15:29: NanosecondsPerSecond * SecondsPerYear (constant 31556952000000000 of type int) overflows int
make: *** [build-arm] Error 1
```

After

```shell
$ make build-arm
--> Updating go.mod
```
@jcstein
Copy link
Member

jcstein commented Aug 28, 2023

Nick is running into this error on an android, I'd imagine maybe the make build-arm isn't reflected in the makefile for node?

@rootulp
Copy link
Collaborator Author

rootulp commented Aug 28, 2023

You're right the celestia-node Makefile doesn't have a make build-arm command. Clarifying question: is Nick trying to run celestia-node or celestia-app on Android?

If celestia-node, I think we should open an issue in celestia-node repo.
If celestia-app, I think we need a new issue in celestia-app and I can investigate.

@rootulp
Copy link
Collaborator Author

rootulp commented Aug 29, 2023

Circling back on this for visibility @jcstein:

  • @nwhite1 was trying to run celestia-node on Android.
  • The earliest celestia-app release with this fix was v1.0.0-rc10 so releases >= v1.0.0-rc10 shouldn't encounter this error. Releases < v1.0.0-rc10 will encounter this error.
  • I looked at a few releases of celestia-node to see what version of celestia-app they depend on.
    • These celestia-node releases should not work: v0.11.0-rc6, v0.11.0-rc7, v0.11.0-rc8
    • These celestia-node releases should work: v0.11.0-rc8-arabica-improvements, v0.11.0-rc9

If ya'll still observe this error on celestia-node releases that should work, can you please open a new GH issue?

@jcstein
Copy link
Member

jcstein commented Aug 29, 2023

hey @rootulp thanks for following up here. i don’t think an issue is needed, and will see if one of the newer versions works!

@jcstein
Copy link
Member

jcstein commented Aug 29, 2023

assuming it doesn’t happen on a release where it is fixed

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.

There is still a overflow issues on the latest commit:
4 participants