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

go/common/cbor: Bump decoding limits #4478

Merged
merged 1 commit into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/4478.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/common/cbor: Bump decoding limits
6 changes: 4 additions & 2 deletions go/common/cbor/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ var (
IndefLength: cbor.IndefLengthForbidden,
TagsMd: cbor.TagsForbidden,
ExtraReturnErrors: cbor.ExtraDecErrorUnknownField,
MaxArrayElements: 10_000_000, // Usually limited by blob size limits anyway.
MaxMapPairs: 10_000_000, // Usually limited by blob size limits anyway.
}

// decOptionsTrusted are decoding options for TRUSTED inputs. They are only used when explicitly
// requested by using the UnmarshalTrusted method.
decOptionsTrusted = cbor.DecOptions{
MaxArrayElements: 134217728, // Maximum allowed.
MaxMapPairs: 134217728, // Maximum allowed.
MaxArrayElements: 2147483647, // Maximum allowed.
MaxMapPairs: 2147483647, // Maximum allowed.
}

encMode cbor.EncMode
Expand Down
12 changes: 10 additions & 2 deletions go/common/cbor/cbor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ func TestOutOfMem1(t *testing.T) {
require := require.New(t)

var f []byte
err := Unmarshal([]byte("\x9b\x00\x00000000"), f)
err := Unmarshal([]byte("\x9b\x00\x00000000"), &f)
require.Error(err, "Invalid CBOR input should fail")
}

func TestOutOfMem2(t *testing.T) {
require := require.New(t)

var f []byte
err := Unmarshal([]byte("\x9b\x00\x00\x81112233"), f)
err := Unmarshal([]byte("\x9b\x00\x00\x81112233"), &f)
require.Error(err, "Invalid CBOR input should fail")
}

func TestOutOfMem3(t *testing.T) {
require := require.New(t)

var f []byte
err := Unmarshal([]byte("\x9a\x00\x98\x96\x80foobar"), &f)
require.Error(err, "Invalid CBOR input should fail")
}

Expand Down