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

bugfix: fields with tag "write_empty" are not marshaled correctly #287

Merged
merged 1 commit into from
Sep 12, 2019

Conversation

rickyyangz
Copy link
Contributor

as the titled described, the implementation of write_empty is not correct, fields with write_empty tag may still be marshaled to empty bytes.

func TestForceWriteEmpty(t *testing.T) {
type InnerWriteEmpty struct {
    // sth. that isn't zero-len if default, e.g. fixed32:
    ValIn int32 `amino:"write_empty" binary:"fixed32"`
}

type OuterWriteEmpty struct {
    In  InnerWriteEmpty `amino:"write_empty"`
    Val int             `amino:"write_empty" binary:"fixed32"`
}

cdc := amino.NewCodec()

b, err := cdc.MarshalBinaryBare(OuterWriteEmpty{})
assert.NoError(t, err)
assert.Equal(t, []byte{10, 5, 13, 0, 0, 0, 0, 16, 0}, b)

b, err = cdc.MarshalBinaryBare(InnerWriteEmpty{})
assert.NoError(t, err)
assert.Equal(t, []byte{13, 0, 0, 0, 0,}, b)
}

the result is

Error:          Not equal: 
                        expected: []byte{0xa, 0x5, 0xd, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0}
                        actual  : []byte{0xa, 0x5, 0xd, 0x0, 0x0, 0x0, 0x0}

Error:          Not equal: 
                        expected: []byte{0xd, 0x0, 0x0, 0x0, 0x0}
                        actual  : []byte(nil)

@rickyyangz
Copy link
Contributor Author

btw, I submitted a report to the bug bounty program

binary_test.go Outdated Show resolved Hide resolved
@zmanian
Copy link
Contributor

zmanian commented Sep 12, 2019

We should consider back porting this fix to v0.15 and consider doing v0.16 release to fix this.

@rickyyangz is this bug blocking you?

@zmanian zmanian merged commit ccb336d into tendermint:master Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants