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: unmarshal does not correctly zero out slices #24155

Closed
JeremyLoy opened this issue Feb 27, 2018 · 3 comments
Closed

encoding/json: unmarshal does not correctly zero out slices #24155

JeremyLoy opened this issue Feb 27, 2018 · 3 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@JeremyLoy
Copy link

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

1.10

Does this issue reproduce with the latest release?

1.10 is the latest release at the time of this submission

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

darwin/amd64

What did you do?

play.golang example showing address reuse

  1. Unmarshal or Decode JSON into a MyStruct
  2. Unmarshal or Decode a second JSON into the same variable
  3. Note how the address of the slice did not change

play.golang example demoing bad behavior

  1. Unmarshal or Decode JSON into a MyStruct
  2. Add that struct to a slice of MyStruct
  3. Unmarshal or Decode a second JSON into the same variable
  4. Note how the address of the slice did not change
  5. Note how the underlying arrays have merged
  6. Note how the Name field was deserialized correctly and was not overridden

What did you expect to see?

data1 and data2 were deserialized into structs, and appended to a slice without overriding each other.

What did you see instead?

data2's alphabet values overwrote elements in data1's alphabet. This is in contrast to how name behaves.

@bradfitz
Copy link
Contributor

This sounds familiar. Is this a dup of #21092?

@bradfitz bradfitz changed the title JSON package does not correctly zero out slices encoding/json: unmarshal does not correctly zero out slices Feb 27, 2018
@bradfitz bradfitz added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Feb 27, 2018
@JeremyLoy
Copy link
Author

@bradfitz Yes, I believe so. Thanks for pointing me towards that! Is there anything I can do other than a 👍 to bring more attention to #21092?

@bradfitz
Copy link
Contributor

Nope. It's already marked as needing a fix for the next release. Thanks!

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

3 participants