go-ozzo / ozzo-config

A Go (golang) package supporting layered application configuration in popular formats, such as JSON, YAML, TOML.
MIT License
111 stars 18 forks source link

Leak in reflect when using Load() against JSON file (on a non-Register()ed type) #8

Open igorastds opened 7 years ago

igorastds commented 7 years ago

TL;DR: bug.json: {"Head": {"StepSize": 2,"Hacks": {"Backup": {"A": 1,"Users": [1, 2, 3, 4],"S":"S"}}}}

    cfg.Load("bug.json")
        foo struct { Hacks struct { Backup struct { Users []int } } }
x:
    cfg.Configure(&foo, "Head")
    if len(foo.Hacks.Backup.Users) < 1 {
        tries++
        goto x
    }
    log.Println(fmt.Sprintf("ok done, took %d tries, got %v", tries, foo.Hacks.Backup.Users))

The results to get this structure parsed are varying between taking 8000 - 160000 tries on my machine, and this is not even supposed to work I guess. Test code: http://pastebin.com/FLQVtDYZ, tested on 1.6.2 and 1.8

qiangxue commented 7 years ago

Issue confirmed. I will look into it. Thanks!