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/json: SyntaxError.Offset is wrong when decoding stream #44811

Open
santhosh-tekuri opened this issue Mar 5, 2021 · 4 comments · May be fixed by #48950
Open

encoding/json: SyntaxError.Offset is wrong when decoding stream #44811

santhosh-tekuri opened this issue Mar 5, 2021 · 4 comments · May be fixed by #48950

Comments

@santhosh-tekuri
Copy link
Contributor

@santhosh-tekuri santhosh-tekuri commented Mar 5, 2021

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

$ go version
go version go1.15.6 darwin/amd64

Does this issue reproduce with the latest release?

yes. reproducable on playground with 1.16 version

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/santhosh/Library/Caches/go-build"
GOENV="/Users/santhosh/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/santhosh/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/santhosh/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/santhosh/json/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z6/vfg99x7d2szf54dd2yms9j5r0000gn/T/go-build029684704=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

https://play.golang.org/p/cPDdjRRl1Rg

What did you expect to see?

offset: 34

What did you see instead?

offset: 24

@networkimprov
Copy link

@networkimprov networkimprov commented Mar 5, 2021

@dsnet
Copy link
Member

@dsnet dsnet commented Mar 5, 2021

Yep. That looks like a bug.

AlexanderYastrebov added a commit to AlexanderYastrebov/go that referenced this issue Oct 13, 2021
Stream decoder does not count whitespaces, empty objects and arrays
in syntax error offset. This change removes offset tracking from the
scanner and relies on the calling code to provide the correct value.

Fixes golang#44811
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 13, 2021

Change https://golang.org/cl/355729 mentions this issue: encoding/json: calculate correct SyntaxError.Offset in the stream

@AlexanderYastrebov
Copy link
Contributor

@AlexanderYastrebov AlexanderYastrebov commented Oct 13, 2021

I've found an apparent duplicate #34543 for which https://go-review.googlesource.com/c/go/+/284078/ attempts to add dec.scan.bytes++ in every possible place while my take abandons scanner offset tracking altogether.

AlexanderYastrebov added a commit to AlexanderYastrebov/go that referenced this issue Oct 13, 2021
Stream decoder does not count whitespaces, empty objects and arrays
in syntax error offset. This change removes offset tracking from the
scanner and relies on the calling code to provide the correct value.

Fixes golang#44811, golang#34543
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.

6 participants