-
Notifications
You must be signed in to change notification settings - Fork 9
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
Clear decoder buffer #166
Clear decoder buffer #166
Conversation
@lukechampine I think there's another potential attack vector where a huge prefix for an array is sent that is technically smaller than For example, when decoding a block sent by a peer, |
The old encoder took a different approach: https://github.com/NebulousLabs/Sia/blob/master/encoding/marshal.go#L341 // NextPrefix is like NextUint64, but performs sanity checks on the prefix.
// Specifically, if the prefix multiplied by elemSize exceeds MaxSliceSize,
// NextPrefix returns 0 and sets d.Err().
func (d *Decoder) NextPrefix(elemSize uintptr) uint64 { But this kinda sucked because your callsites end up looking like: addrs := make([]types.Address, d.NextPrefix(unsafe.Sizeof(types.Address{})) i.e. you had to import addrs := d.ReadSlice[[]types.Address]() ...but Go doesn't support generic methods, so I guess you'd have to do Backing up, though: I did consider this issue when I implemented the decoder. My feeling at the time was that, although it does allow amplification attacks, the amplification is linear, and in practice the scaling factor is not enormous; the biggest is probably But is this actually a problem? When you call |
15a039b
to
223630e
Compare
Ensures the decoder's buffer is cleared when
Read
encounters an error. This should fix OOM issues we're seeing when syncing Mainnet. It may also fix SiaFoundation/hostd#406, but I haven't looked deep into that one yet.