All slice types must have limits
The XDR unmarshaller allocates a []T when it sees a slice type and reads the expected length, so we must always limit the length in order to avoid allocating too much memory when encountering corruption.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
package protocol
|
||||
|
||||
import "github.com/calmh/xdr"
|
||||
|
||||
// This stuff is hacked up manually because genxdr doesn't support 'type
|
||||
// Vector []Counter' declarations and it was tricky when I tried to add it...
|
||||
|
||||
@@ -28,6 +30,9 @@ func (v Vector) EncodeXDRInto(w xdrWriter) (int, error) {
|
||||
// DecodeXDRFrom decodes the XDR objects from the given reader into itself.
|
||||
func (v *Vector) DecodeXDRFrom(r xdrReader) error {
|
||||
l := int(r.ReadUint32())
|
||||
if l > 1e6 {
|
||||
return xdr.ElementSizeExceeded("number of counters", l, 1e6)
|
||||
}
|
||||
n := make(Vector, l)
|
||||
for i := range n {
|
||||
n[i].ID = r.ReadUint64()
|
||||
|
||||
Reference in New Issue
Block a user