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: runtime error: index out of range [24] with length 24 #63420

Closed
clarkmcc opened this issue Oct 6, 2023 · 5 comments
Closed

encoding/json: runtime error: index out of range [24] with length 24 #63420

clarkmcc opened this issue Oct 6, 2023 · 5 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@clarkmcc
Copy link

clarkmcc commented Oct 6, 2023

First of all, I apologize for the ambiguity in this issue. This was caught by an error reporting system in production, it's the first time we've seen this issue and our system has been running for years. This code path is called about ~100,000 times per day so whatever the issue is, it's obscure.

If you need more information, I'll do my best to collect it, but I'm hoping maybe the stack trace will point someone in the right direction on the out of bound error.

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

$ go version

1.21

Does this issue reproduce with the latest release?

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

go env Output
$ go env

What did you do?

d.CurrentFoobar is of type map[string]interface{} and we're trying to unmarshal it into another type. We do a lot of work with primitive.ObjectID so I suspect the issue is related to that.

out = &Foobar{}
b, err := json.Marshal(d.CurrentFoobar)
if err != nil {
	return nil, err
}
err = json.Unmarshal(b, out)
if err != nil {
	return nil, err
}

What did you expect to see?

I would have expected a marshaling error to be returned, not a panic.

What did you see instead?

runtime error: index out of range [24] with length 24

at encoding/json.(*encodeState).marshal.func1 ( /usr/local/go/src/encoding/json/encode.go:291 )
at .panic ( /usr/local/go/src/runtime/panic.go:914 )
at encoding/json.mapEncoder.encode ( /usr/local/go/src/encoding/json/encode.go:745 )
at encoding/json.(*encodeState).reflectValue ( /usr/local/go/src/encoding/json/encode.go:323 )
at encoding/json.interfaceEncoder ( /usr/local/go/src/encoding/json/encode.go:660 )
at encoding/json.mapEncoder.encode ( /usr/local/go/src/encoding/json/encode.go:759 )
at encoding/json.(*encodeState).reflectValue ( /usr/local/go/src/encoding/json/encode.go:323 )
at encoding/json.(*encodeState).marshal ( /usr/local/go/src/encoding/json/encode.go:295 )
at encoding/json.Marshal ( /usr/local/go/src/encoding/json/encode.go:162 )
...
@seankhliao
Copy link
Member

That stacktrace references this piece of code, which doesn't look like something that can go wrong unless the map was modified during encoding. It sounds more likely to be a race condition within your code?

sv := make([]reflectWithString, v.Len())
mi := v.MapRange()
for i := 0; mi.Next(); i++ {
sv[i].k = mi.Key()
sv[i].v = mi.Value()

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 6, 2023
@thediveo
Copy link

thediveo commented Oct 6, 2023

maybe #63379, seems to be the same crash site in the trace if I'm reading correctly.

@seankhliao
Copy link
Member

seankhliao commented Oct 6, 2023

#63379 crashes at a subslice out of bounds, this is a slice index out of bounds.

@andig

This comment was marked as resolved.

@clarkmcc
Copy link
Author

clarkmcc commented Oct 6, 2023

@seankhliao seems at least theoretically possible after a quick look through my code. Closing for now since I agree the crash site doesn't seem like it should be able to crash with a stable v.

@clarkmcc clarkmcc closed this as completed Oct 6, 2023
@golang golang locked and limited conversation to collaborators Oct 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants