Open
Description
Please answer these questions before submitting your issue. Thanks!
- What version of Go are you using (
go version
)?
go version devel +67f799c Tue Jul 26 00:18:42 2016 +0000 linux/amd64
But it also affects the version of 1.6 on the playground at the moment.
- What operating system and processor architecture are you using (
go env
)?
GOARCH="amd64"
GOBIN="/home/sam/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/sam"
GORACE=""
GOROOT="/home/sam/src/go"
GOTOOLDIR="/home/sam/src/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build800221808=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
- What did you do?
When attempting to unmarshal XML into a struct that is composed of another struct that has an XMLName field that has a field number greater than or equal to the number of fields in the original struct, finfo.Value
panics because reflect tries to get the value of the field in the parent struct at the location of XMLName
in the child struct (which has a field index that is out of bounds when applied to the parent struct).
For example, this contrived example panics:
package main
import (
"encoding/xml"
)
type IQ struct {
Type string `xml:"type,attr"`
XMLName xml.Name `xml:"iq"`
}
func main() {
resp := struct {
IQ
}{}
xml.Unmarshal([]byte(`<iq/>`), &resp)
}
but if we move the fields around:
type IQ struct {
XMLName xml.Name `xml:"iq"`
Type string `xml:"type,attr"`
}
it works (Playground)