mitchellh / mapstructure

Go library for decoding generic map values into native Go structures and vice versa.
https://gist.github.com/mitchellh/90029601268e59a29e64e55bab1c5bdc
MIT License
7.89k stars 669 forks source link

Decoding array of slices causes panic #340

Open nolag opened 11 months ago

nolag commented 11 months ago

The simplest way I can re-do it is below. It causes a panic [1]

package main

import (
    "fmt"
    "github.com/mitchellh/mapstructure"
)

type Foo struct {
    B [2][]byte
}

func main() {
    f := &Foo{}
    if err := mapstructure.Decode(map[string]interface{}{"B": [2][]byte{{1, 2}, {3, 4}}}, &f); err != nil {
        panic(err)
    }
    fmt.Println(f.B)
}

[1]

panic: runtime error: comparing uncomparable type [2][]uint8

goroutine 1 [running]:
github.com/mitchellh/mapstructure.(*Decoder).decodeArray(0x1400006e1f8, {0x1012344ac, 0x1}, {0x10129cfe0, 0x14000421d10}, {0x10129cfe0?, 0x14000421cb0?, 0x1009eff8c?})
        <user>//go/pkg/mod/github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:1164 +0x1f8
github.com/mitchellh/mapstructure.(*Decoder).decode(0x1400006e1f8, {0x1012344ac, 0x1}, {0x10129cfe0?, 0x14000421d10?}, {0x10129cfe0?, 0x14000421cb0?, 0x10095c388?})
        <user>//go/pkg/mod/github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:490 +0x1b8
github.com/mitchellh/mapstructure.(*Decoder).decodeStructFromMap(0x1400006e1f8, {0x0, 0x0}, {0x1012c7380?, 0x14000421ce0?, 0x100964b10?}, {0x1012e9e80?, 0x14000421cb0?, 0x140005cdb18?})
        <user>//go/pkg/mod/github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:1411 +0x718
github.com/mitchellh/mapstructure.(*Decoder).decodeStruct(0x140005cdc48?, {0x0, 0x0}, {0x1012c7380?, 0x14000421ce0?}, {0x1012e9e80?, 0x14000421cb0?, 0x6050f655bb53ef15?})
        <user>//go/pkg/mod/github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:1235 +0x3ec
github.com/mitchellh/mapstructure.(*Decoder).decode(0x1400006e1f8, {0x0, 0x0}, {0x1012c7380?, 0x14000421ce0?}, {0x1012e9e80?, 0x14000421cb0?, 0x100964b10?})
        <user>//go/pkg/mod/github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:482 +0x218
github.com/mitchellh/mapstructure.(*Decoder).decodePtr(0x1400006e1f8, {0x0, 0x0}, {0x1012c7380, 0x14000421ce0}, {0x101270c40?, 0x1400006e1e8?, 0x101b84130?})
        <user>//go/pkg/mod/github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:1052 +0x3b8
github.com/mitchellh/mapstructure.(*Decoder).decode(0x1400006e1f8, {0x0, 0x0}, {0x1012c7380?, 0x14000421ce0?}, {0x101270c40?, 0x1400006e1e8?, 0x10138a120?})
        <user>//go/pkg/mod/github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:486 +0x1e8
github.com/mitchellh/mapstructure.(*Decoder).Decode(0x1400006e1f8, {0x1012c7380, 0x14000421ce0})
        <user>//go/pkg/mod/github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:417 +0xb8
github.com/mitchellh/mapstructure.Decode({0x1012c7380, 0x14000421ce0}, {0x101280080?, 0x1400006e1e8})
        <user>//go/pkg/mod/github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:317 +0x8c
main.main()
        <user>//go/src/playground/entry.go:14 +0x144