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

Comments

Projects
None yet
3 participants
@JeremyLoy
Copy link

commented Feb 27, 2018

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

This comment has been minimized.

Copy link
Member

commented Feb 27, 2018

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

@JeremyLoy

This comment has been minimized.

Copy link
Author

commented Feb 27, 2018

@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

This comment has been minimized.

Copy link
Member

commented Feb 27, 2018

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.
You can’t perform that action at this time.