pelletier / go-toml

Go library for the TOML file format
https://github.com/pelletier/go-toml
Other
1.68k stars 208 forks source link

v2: panic unmarshaling inline table to string #850

Closed NathanBaulch closed 1 year ago

NathanBaulch commented 1 year ago

Describe the bug

panic: subslice address (0) is before data address (824636779408)
goroutine 1 [running]:
github.com/pelletier/go-toml/v2/internal/danger.SubsliceOffset({0xc0002eab90, 0x8, 0x8}, {0x0, 0x0, 0x0})
        C:/Users/Nathan/go/pkg/mod/github.com/pelletier/go-toml/v2@v2.0.6/internal/danger/danger.go:16 +0x273
github.com/pelletier/go-toml/v2.wrapDecodeError({0xc0002eab90, 0x8, 0x8}, 0xc0002cd0c0)
        C:/Users/Nathan/go/pkg/mod/github.com/pelletier/go-toml/v2@v2.0.6/errors.go:91 +0x5c
github.com/pelletier/go-toml/v2.(*decoder).FromParser(0xc000207f00, {0xea01a0?, 0xc00000a4b8?})
        C:/Users/Nathan/go/pkg/mod/github.com/pelletier/go-toml/v2@v2.0.6/unmarshaler.go:216 +0x24c
github.com/pelletier/go-toml/v2.Unmarshal({0xc0002eab90, 0x8, 0x8}, {0xea01a0, 0xc00000a4b8})
        C:/Users/Nathan/go/pkg/mod/github.com/pelletier/go-toml/v2@v2.0.6/unmarshaler.go:28 +0x11a
main.main()

To Reproduce

data := make(map[string]string)
_ = toml.Unmarshal([]byte("foo = {}"), &data)

Expected behavior A meaningful error.

Versions

Additional context Similar to #581 and #588.

pelletier commented 1 year ago

Thanks for reporting this bug! I've merged https://github.com/pelletier/go-toml/commit/8a416daa69794fc1b10dbd0ad77048d23328637d, which should correct the problem. Feel free to reopen this issue if it doesn't.