dedis / protobuf

Reflection-based Protocol Buffers for Go
GNU General Public License v2.0
76 stars 15 forks source link

byte slices have a capacity that overflows onto the next field #40

Closed jeffallen closed 6 years ago

jeffallen commented 6 years ago

If two byte slices are next to each other in the struct, upon decoding the first byte slice will have a cap that overflows onto the second slice. If the first byte slice is then stretched with append such that it ends up smaller than the cap of the first slice, the second slice will be overwritten.

The fix is that on Decode, we must always return slices with cap == len, so that if the caller wants to extend the slice, he/she will be obliged to copy it.