Skip to content

encoding/xml: copyValue uses int16 causing error on strconv.ParseInt #32041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alfarom256 opened this issue May 14, 2019 · 3 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@alfarom256
Copy link

What version of Go are you using (go version)?

> go version
go version go1.12.5 windows/amd64

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Michael\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Michael\go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Michael\AppData\Local\Temp\go-build556838694=/tmp/go-build -gno-record-gcc-switches

What did you do?

Unmarshalled an XML node containing the int value 258387

What did you expect to see?

The string "258387" parsed correctly to it's integer value.

What did you see instead?

When parsing an XML attribute, the xml.Unmarshal method uses a signed 16b int for the destination of ParseInt.
When the parsed integer is > MAX_16 an (expected for the size of dst) error is thrown.
Not sure if this is reproducible every time an int is parsed > MAX_16, rather in my large (40MB) XML file, this is a consistent occurrence with every int.

in xml/read.go:

		itmp, err := strconv.ParseInt(strings.TrimSpace(string(src)), 10, dst.Type().Bits())
		if err != nil {
			return err
		}

the value presented by the debugger during runtime:

dst0.Type():
...
size = 2
align = 2
... trimmed
fieldAlign = 2
...

call stack:

encoding/xml.copyValue at read.go:618
encoding/xml.(*Decoder).unmarshal at read.go:574
encoding/xml.(*Decoder).unmarshalPath at read.go:685
encoding/xml.(*Decoder).unmarshal at read.go:519
encoding/xml.(*Decoder).unmarshalPath at read.go:685
encoding/xml.(*Decoder).unmarshal at read.go:519
encoding/xml.(*Decoder).unmarshalPath at read.go:685
encoding/xml.(*Decoder).unmarshal at read.go:519
encoding/xml.(*Decoder).DecodeElement at read.go:146
encoding/xml.(*Decoder).Decode at read.go:134
encoding/xml.Unmarshal at read.go:128
... call back to main, trimmed for brevity
@alfarom256
Copy link
Author

I should add, for dst0 and dst:

// line 602-603
func copyValue(dst reflect.Value, src []byte) (err error) {
	dst0 := dst

both dst0 and dst are equal

@FiloSottile FiloSottile changed the title encoding/xml copyValue uses int16 causing error on strconv.ParseInt encoding/xml: copyValue uses int16 causing error on strconv.ParseInt May 14, 2019
@FiloSottile
Copy link
Contributor

@alfarom256 can you provide an example input that causes an error, ideally in a play.golang.org snippet?

@FiloSottile FiloSottile added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 14, 2019
@FiloSottile FiloSottile modified the milestones: Unplanned, Go1.14 May 14, 2019
@FiloSottile FiloSottile added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 14, 2019
@alfarom256
Copy link
Author

Please excuse my report, there was a type assigned in a buried struct.
I changed it to int32 and the error was fixed.
User error strikes again!

@golang golang locked and limited conversation to collaborators May 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants