Skip to content

Commit 9b85219

Browse files
committed
Merge branch 'cbor-alloc-limits'
2 parents 8717756 + 665d606 commit 9b85219

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

cbor/cborDecoderTerminals.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ func (d *Decoder) decodeBytesOrStringIndefinite(bs []byte, majorWanted byte) (bs
124124
}
125125
oldLen := len(bs)
126126
newLen := oldLen + n
127+
if n > 33554432 {
128+
return nil, fmt.Errorf("cbor: decoding rejected oversized indefinite string/bytes field: %d is too large", n)
129+
}
127130
if newLen > cap(bs) {
128131
bs2 := make([]byte, newLen, 2*cap(bs)+n)
129132
copy(bs2, bs)
@@ -168,6 +171,9 @@ func (d *Decoder) decodeBytes(majorByte byte) (bs []byte, err error) {
168171
if err != nil {
169172
return nil, err
170173
}
174+
if n > 33554432 {
175+
return nil, fmt.Errorf("cbor: decoding rejected oversized byte field: %d is too large", n)
176+
}
171177
return d.r.Readn(n)
172178
}
173179

@@ -177,6 +183,9 @@ func (d *Decoder) decodeString(majorByte byte) (s string, err error) {
177183
if err != nil {
178184
return "", err
179185
}
186+
if n > 33554432 {
187+
return "", fmt.Errorf("cbor: decoding rejected oversized string field: %d is too large", n)
188+
}
180189
bs, err := d.r.Readnzc(n)
181190
return string(bs), err
182191
}

0 commit comments

Comments
 (0)