Skip to content

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

Merged
zmanian merged 1 commit intotendermint:masterfrom
rickyyangz:write_empty
Sep 12, 2019
Merged

bugfix: fields with tag "write_empty" are not marshaled correctly#287
zmanian merged 1 commit intotendermint:masterfrom
rickyyangz:write_empty

Conversation

@rickyyangz
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

btw, I submitted a report to the bug bounty program

Comment thread binary_test.go Outdated
@zmanian
Copy link
Copy Markdown
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.

3 participants