Repository: fxamacker/cbor (go)

Issue:
feature: increase user-configurable CBOR limit for MaxArrayElements and MaxMapPairs
**Is your feature request related to a problem? Please describe.**

Current limit of DecOptions.MaxArrayElements and DecOptions.MaxMapPairs is:  
* default limit = 131072
* max limit user can set =  134217728

At least one project already set limits to the max allowed.  Also, schema-less binary formats like CBOR will be used in large systems and for use cases not initially anticipated.

**Describe the solution you'd like**

Continue to keep default limits reasonably safe & usable, only increase user-configurable max.

Increase limit of DecOptions.MaxArrayElements and DecOptions.MaxMapPairs to:  
* default limit = 131072 (unchanged)
* max limit user can set =  2147483647 (0x7FFFFFFF)

**Describe alternatives you've considered**

* Ignore this until a user requests an increase.  
* Other (smaller) values were too arbitrary compared to the largest positive signed 32-bit int.


Pull request description:
Increase MaxArrayElements and MaxMapPairs max limits
Increased MaxArrayElements and MaxMapPairs max limits from 134217728 to 2147483647.

Default limits are unchanged.

Closes #207



Patch:
diff --git a/README.md b/README.md
index 976471d..5bd310c 100644
--- a/README.md
+++ b/README.md
@@ -696,13 +696,13 @@ Go's `time` package provides `IsZero` function, which reports whether t represen
 
 | DecOptions.MaxArrayElements | Description |
 | --------------------------- | ----------- |
-| 131072 (default) | allowed setting is [16, 134217728] |
+| 131072 (default) | allowed setting is [16, 2147483647] |
 
 <br>
 
 | DecOptions.MaxMapPairs | Description |
 | ---------------------- | ----------- |
-| 131072 (default) | allowed setting is [16, 134217728] |
+| 131072 (default) | allowed setting is [16, 2147483647] |
 
 ### Encoding Options
 
diff --git a/decode.go b/decode.go
index 21fb65c..6be91a2 100644
--- a/decode.go
+++ b/decode.go
@@ -269,11 +269,11 @@ type DecOptions struct {
 	MaxNestedLevels int
 
 	// MaxArrayElements specifies the max number of elements for CBOR arrays.
-	// Default is 128*1024=131072 and it can be set to [16, 134217728]
+	// Default is 128*1024=131072 and it can be set to [16, 2147483647]
 	MaxArrayElements int
 
 	// MaxMapPairs specifies the max number of key-value pairs for CBOR maps.
-	// Default is 128*1024=131072 and it can be set to [16, 134217728]
+	// Default is 128*1024=131072 and it can be set to [16, 2147483647]
 	MaxMapPairs int
 
 	// IndefLength specifies whether to allow indefinite length CBOR items.
@@ -347,11 +347,11 @@ func (opts DecOptions) DecModeWithSharedTags(tags TagSet) (DecMode, error) {
 const (
 	defaultMaxArrayElements = 131072
 	minMaxArrayElements     = 16
-	maxMaxArrayElements     = 134217728
+	maxMaxArrayElements     = 2147483647
 
 	defaultMaxMapPairs = 131072
 	minMaxMapPairs     = 16
-	maxMaxMapPairs     = 134217728
+	maxMaxMapPairs     = 2147483647
 )
 
 func (opts DecOptions) decMode() (*decMode, error) {


Test patch:
diff --git a/decode_test.go b/decode_test.go
index a4b6603..01537df 100644
--- a/decode_test.go
+++ b/decode_test.go
@@ -3068,12 +3068,12 @@ func TestDecModeInvalidMaxMapPairs(t *testing.T) {
 		{
 			name:         "MaxMapPairs < 16",
 			opts:         DecOptions{MaxMapPairs: 1},
-			wantErrorMsg: "cbor: invalid MaxMapPairs 1 (range is [16, 134217728])",
+			wantErrorMsg: "cbor: invalid MaxMapPairs 1 (range is [16, 2147483647])",
 		},
 		{
-			name:         "MaxMapPairs > 134217728",
-			opts:         DecOptions{MaxMapPairs: 134217729},
-			wantErrorMsg: "cbor: invalid MaxMapPairs 134217729 (range is [16, 134217728])",
+			name:         "MaxMapPairs > 2147483647",
+			opts:         DecOptions{MaxMapPairs: 2147483648},
+			wantErrorMsg: "cbor: invalid MaxMapPairs 2147483648 (range is [16, 2147483647])",
 		},
 	}
 	for _, tc := range testCases {
@@ -3109,12 +3109,12 @@ func TestDecModeInvalidMaxArrayElements(t *testing.T) {
 		{
 			name:         "MaxArrayElements < 16",
 			opts:         DecOptions{MaxArrayElements: 1},
-			wantErrorMsg: "cbor: invalid MaxArrayElements 1 (range is [16, 134217728])",
+			wantErrorMsg: "cbor: invalid MaxArrayElements 1 (range is [16, 2147483647])",
 		},
 		{
-			name:         "MaxArrayElements > 134217728",
-			opts:         DecOptions{MaxArrayElements: 134217729},
-			wantErrorMsg: "cbor: invalid MaxArrayElements 134217729 (range is [16, 134217728])",
+			name:         "MaxArrayElements > 2147483647",
+			opts:         DecOptions{MaxArrayElements: 2147483648},
+			wantErrorMsg: "cbor: invalid MaxArrayElements 2147483648 (range is [16, 2147483647])",
 		},
 	}
 	for _, tc := range testCases {