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

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

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

santhosh-tekuri opened this issue Mar 5, 2021 · 5 comments · May be fixed by #48950
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@santhosh-tekuri
Copy link
Contributor

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

cc @mvdan @dsnet

@mvdan mvdan added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 5, 2021
@dsnet
Copy link
Member

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

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

@AlexanderYastrebov
Copy link
Contributor

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
@seankhliao
Copy link
Member

Duplicate of #34543

@seankhliao seankhliao marked this as a duplicate of #34543 Aug 20, 2022
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants