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

x/bank/types: AddressFromBalancesStore is susceptible to bounds crashes if fed an empty byte sequence or one with a false length #9062

Closed
3 of 4 tasks
odeke-em opened this issue Apr 7, 2021 · 0 comments

Comments

@odeke-em
Copy link
Collaborator

odeke-em commented Apr 7, 2021

Summary of Bug

Coming here from fuzzing by my colleague @cuonglm who found a vector #9060
in which AddressFromBalancesStore naively just tries to slice values without bounds checking. If we look at the code

func AddressFromBalancesStore(key []byte) sdk.AccAddress {
addrLen := key[0]
addr := key[1 : addrLen+1]
return sdk.AccAddress(addr)
}

There are 2 problems:
a) If an empty byte sequence is passed it, it crashes
b) If I lie about the length of that sequence, we'll get a panic say with

_ = banktypes.AddressFromBalancesStore([]byte{0x7f, 0x10, 0x12, 0x74})

The second form is most dangerous because on a quick audit of data flowing through, if at all a len(...) check were made or examining what's retrieved from genesis files, it would look okay but really it is deceptive about the length of the slice hence would crash

Version

All versions

Steps to Reproduce

_ = banktypes.AddressFromBalancesStore([]byte{0x7f, 0x10, 0x12, 0x74})
_ = banktypes.AddressFromBalancesStore(nil)
_ = banktypes.AddressFromBalancesStore([]byte{})

I kindly request that we backport the fix for it.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant