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/gob: debug function prints uint values incorrectly #21392

Closed
drosseau opened this issue Aug 10, 2017 · 3 comments
Closed

encoding/gob: debug function prints uint values incorrectly #21392

drosseau opened this issue Aug 10, 2017 · 3 comments

Comments

@drosseau
Copy link

@drosseau drosseau commented Aug 10, 2017

Please answer these questions before submitting your issue. Thanks!

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

$ go version
go version go1.8 linux/amd64

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

$ go env
GOARCH="amd64"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build871485140=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

Use the Debug function in encoding/gob to try to view a gob. A simplified gob that has the error is here:

package main

import (
	"bytes"
	"encoding/gob"
)

var gobBytes = []byte{0x3, 0x6, 0x0, 0xa}


func main() {
	gob.Debug(bytes.NewReader(gobBytes))
}

(Sorry I can't put this in the playground as you need to build the gob package without the build guard for Debug)

What did you expect to see?

Output of Debug should have been

Start of debugging
10

What did you see instead?

Start of debugging
5

Basically this was being treated as an integer and not an unsigned integer and so decoded with the

y := (x >> 1)
if x&1 != 0 {
   y = ^y
}

integer decoding method.

@ALTree
Copy link
Member

@ALTree ALTree commented Aug 10, 2017

This could be caused by a copy-past error here:

    case tInt:
        x := deb.int64()
        fmt.Fprintf(os.Stderr, "%s%d\n", indent, x)
    case tUint:
        x := deb.int64()
        fmt.Fprintf(os.Stderr, "%s%d\n", indent, x)

Notice how the case tUint branch calls x := deb.int64() instead of x := deb.uint64().

@ALTree ALTree changed the title encoding/gob Debug function prints uint values incorrectly encoding/gob: debug function prints uint values incorrectly Aug 10, 2017
@ALTree ALTree added the NeedsFix label Aug 10, 2017
@drosseau
Copy link
Author

@drosseau drosseau commented Aug 10, 2017

I submitted a fix this and that was the issue. The contribution guidelines just said to open an issue first. I'm not sure if I went about that wrong, if so, sorry.

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 10, 2017

Change https://golang.org/cl/54750 mentions this issue: encoding/gob: Change displaying tUint to use uint instead of int

@ALTree ALTree added this to the Go1.10 milestone Aug 11, 2017
@gopherbot gopherbot closed this in 9515610 Aug 25, 2017
@golang golang locked and limited conversation to collaborators Aug 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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