canonical / gomaasclient

Go MAAS client
Apache License 2.0
19 stars 27 forks source link

fix: unmarshal number leads to int overflow #21

Closed troyanov closed 10 months ago

troyanov commented 10 months 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 10 months 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 10 months ago

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