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

jbub/banking/iban smoke test fails under wasi? #2642

Closed
dkegel-fastly opened this issue Feb 17, 2022 · 2 comments
Closed

jbub/banking/iban smoke test fails under wasi? #2642

dkegel-fastly opened this issue Feb 17, 2022 · 2 comments

Comments

@dkegel-fastly
Copy link
Contributor

With current dev:

$ go run main.go
$ tinygo run main.go
$ tinygo run -target wasi main.go
iban: invalid check digit
$ cat main.go
package main

import "github.com/jbub/banking/iban"

func main() {
	_, err := iban.New("AL50134113214854624345996786")
	if err != nil {
		println(err.Error())
	}
}
@dgryski
Copy link
Member

dgryski commented Feb 17, 2022

I'll take a look at this tonight.

@dgryski
Copy link
Member

dgryski commented Feb 17, 2022

The iban validation code has an integer overflow. On native, int == int64, but wasi is a 32-bit platform, so int == int32.

Upstream can be patched with:

 // https://en.wikipedia.org/wiki/International_Bank_Account_Number#Modulo_operation_on_IBAN
 func calculateMod(value string, code string) (int, error) {
-       var total int
+       var total int64
        for _, c := range reformatIban(value, code) {
-               n := codepointToNum(int(c))
+               n := int64(codepointToNum(int(c)))
                if n < 0 || n > 35 {
                        return 0, ErrInvalidIbanModulo
                }
@@ -102,7 +108,7 @@ func calculateMod(value string, code string) (int, error) {
                        total %= modValue
                }
        }
-       return total % modValue, nil
+       return int(total % modValue), nil
 }

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

No branches or pull requests

2 participants