Skip to content
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

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

Closed
alfarom256 opened this issue May 14, 2019 · 3 comments
Closed

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

alfarom256 opened this issue May 14, 2019 · 3 comments

Comments

@alfarom256
Copy link

@alfarom256 alfarom256 commented May 14, 2019

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

This comment has been minimized.

Copy link
Author

@alfarom256 alfarom256 commented May 14, 2019

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

This comment has been minimized.

Copy link
Member

@FiloSottile FiloSottile commented May 14, 2019

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

@alfarom256

This comment has been minimized.

Copy link
Author

@alfarom256 alfarom256 commented May 14, 2019

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!

@alfarom256 alfarom256 closed this May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.