canonical / gomaasclient

Go MAAS client
Apache License 2.0
23 stars 28 forks source link

fix: unmarshal number leads to int overflow #21

Closed troyanov closed 1 year ago

troyanov commented 1 year ago

Use int64 type for disk size.

Resolves https://github.com/maas/terraform-provider-maas/issues/116

When compiled on a 32-bit platform int will be int32 and will lead to an overflow and JSON unmarshal error:

type Foo struct {
    Size int32
}

func main() {
    data := []byte(`{"Size": 128032178176}`)
    foo := Foo{}
    err := json.Unmarshal(data, &foo)
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println(foo.Size)
}
troyanov commented 1 year ago

Changes look good. Since you opened this one, what about memory (int) and storage, which is float64?!?

Same for VMHostResource

Well, my intent was to fix one particular issue and not all the type issues in the codebase, but if we want to address them all at once, I am fine with it 🙂

skatsaounis commented 1 year ago

Thank you very much for taking care of all the potential overflows. LGTM :beers: