From: Mathias Gibbens <gibmat@debian.org>
Description: Fix tests when run on 32bit architectures
Forwarded: https://github.com/fxamacker/cbor/issues/302
diff --git a/bench_test.go b/bench_test.go
index ad7c465..329f3b3 100644
--- a/bench_test.go
+++ b/bench_test.go
@@ -75,7 +75,7 @@ type SenMLRecord struct {
 
 type T1 struct {
 	T    bool
-	UI   uint
+	UI   uint64
 	I    int
 	F    float64
 	B    []byte
@@ -86,7 +86,7 @@ type T1 struct {
 
 type T2 struct {
 	T    bool              `cbor:"1,keyasint"`
-	UI   uint              `cbor:"2,keyasint"`
+	UI   uint64            `cbor:"2,keyasint"`
 	I    int               `cbor:"3,keyasint"`
 	F    float64           `cbor:"4,keyasint"`
 	B    []byte            `cbor:"5,keyasint"`
@@ -98,7 +98,7 @@ type T2 struct {
 type T3 struct {
 	_    struct{} `cbor:",toarray"`
 	T    bool
-	UI   uint
+	UI   uint64
 	I    int
 	F    float64
 	B    []byte
@@ -386,7 +386,7 @@ func BenchmarkMarshal(b *testing.B) {
 	// Marshal map[string]interface{} to CBOR map
 	m1 := map[string]any{
 		"T":    true,
-		"UI":   uint(18446744073709551615),
+		"UI":   uint64(18446744073709551615),
 		"I":    -1000,
 		"F":    -4.1,
 		"B":    []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26},
@@ -397,7 +397,7 @@ func BenchmarkMarshal(b *testing.B) {
 	// Marshal struct to CBOR map
 	v1 := T1{ //nolint:dupl
 		T:    true,
-		UI:   18446744073709551615,
+		UI:   uint64(18446744073709551615),
 		I:    -1000,
 		F:    -4.1,
 		B:    []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26},
@@ -408,7 +408,7 @@ func BenchmarkMarshal(b *testing.B) {
 	// Marshal map[int]interface{} to CBOR map
 	m2 := map[int]any{
 		1: true,
-		2: uint(18446744073709551615),
+		2: uint64(18446744073709551615),
 		3: -1000,
 		4: -4.1,
 		5: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26},
@@ -419,7 +419,7 @@ func BenchmarkMarshal(b *testing.B) {
 	// Marshal struct keyasint, such as COSE Key and SenML
 	v2 := T2{ //nolint:dupl
 		T:    true,
-		UI:   18446744073709551615,
+		UI:   uint64(18446744073709551615),
 		I:    -1000,
 		F:    -4.1,
 		B:    []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26},
@@ -430,7 +430,7 @@ func BenchmarkMarshal(b *testing.B) {
 	// Marshal []interface to CBOR array.
 	slc := []any{
 		true,
-		uint(18446744073709551615),
+		uint64(18446744073709551615),
 		-1000,
 		-4.1,
 		[]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26},
@@ -441,7 +441,7 @@ func BenchmarkMarshal(b *testing.B) {
 	// Marshal struct toarray to CBOR array, such as signed/maced/encrypted CWT.
 	v3 := T3{ //nolint:dupl
 		T:    true,
-		UI:   18446744073709551615,
+		UI:   uint64(18446744073709551615),
 		I:    -1000,
 		F:    -4.1,
 		B:    []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26},
diff --git a/decode.go b/decode.go
index 3c1c168..b588071 100644
--- a/decode.go
+++ b/decode.go
@@ -785,11 +785,11 @@ type DecOptions struct {
 
 	// MaxArrayElements specifies the max number of elements for CBOR arrays.
 	// Default is 128*1024=131072 and it can be set to [16, 2147483647]
-	MaxArrayElements int
+	MaxArrayElements int64
 
 	// MaxMapPairs specifies the max number of key-value pairs for CBOR maps.
 	// Default is 128*1024=131072 and it can be set to [16, 2147483647]
-	MaxMapPairs int
+	MaxMapPairs int64
 
 	// IndefLength specifies whether to allow indefinite length CBOR items.
 	IndefLength IndefLengthMode
@@ -1014,15 +1014,15 @@ func (opts DecOptions) decMode() (*decMode, error) { //nolint:gocritic // ignore
 	if opts.MaxArrayElements == 0 {
 		opts.MaxArrayElements = defaultMaxArrayElements
 	} else if opts.MaxArrayElements < minMaxArrayElements || opts.MaxArrayElements > maxMaxArrayElements {
-		return nil, errors.New("cbor: invalid MaxArrayElements " + strconv.Itoa(opts.MaxArrayElements) +
-			" (range is [" + strconv.Itoa(minMaxArrayElements) + ", " + strconv.Itoa(maxMaxArrayElements) + "])")
+		return nil, errors.New("cbor: invalid MaxArrayElements " + strconv.FormatInt(opts.MaxArrayElements, 10) +
+			" (range is [" + strconv.Itoa(minMaxArrayElements) + ", " + strconv.FormatInt(maxMaxArrayElements, 10) + "])")
 	}
 
 	if opts.MaxMapPairs == 0 {
 		opts.MaxMapPairs = defaultMaxMapPairs
 	} else if opts.MaxMapPairs < minMaxMapPairs || opts.MaxMapPairs > maxMaxMapPairs {
-		return nil, errors.New("cbor: invalid MaxMapPairs " + strconv.Itoa(opts.MaxMapPairs) +
-			" (range is [" + strconv.Itoa(minMaxMapPairs) + ", " + strconv.Itoa(maxMaxMapPairs) + "])")
+		return nil, errors.New("cbor: invalid MaxMapPairs " + strconv.FormatInt(opts.MaxMapPairs, 10) +
+			" (range is [" + strconv.Itoa(minMaxMapPairs) + ", " + strconv.FormatInt(opts.MaxMapPairs, 10) + "])")
 	}
 
 	if !opts.ExtraReturnErrors.valid() {
@@ -1178,8 +1178,8 @@ type decMode struct {
 	dupMapKey                DupMapKeyMode
 	timeTag                  DecTagMode
 	maxNestedLevels          int
-	maxArrayElements         int
-	maxMapPairs              int
+	maxArrayElements         int64
+	maxMapPairs              int64
 	indefLength              IndefLengthMode
 	tagsMd                   TagsMode
 	intDec                   IntDecMode
@@ -1326,7 +1326,7 @@ func (dm *decMode) NewDecoder(r io.Reader) *Decoder {
 
 type decoder struct {
 	data []byte
-	off  int // next read offset in data
+	off  int64 // next read offset in data
 	dm   *decMode
 
 	// expectedLaterEncodingTags stores a stack of encountered "Expected Later Encoding" tags,
@@ -2129,16 +2129,16 @@ func (d *decoder) parse(skipSelfDescribedTag bool) (any, error) { //nolint:gocyc
 func (d *decoder) parseByteString() ([]byte, bool) {
 	_, _, val, indefiniteLength := d.getHeadWithIndefiniteLengthFlag()
 	if !indefiniteLength {
-		b := d.data[d.off : d.off+int(val)]
-		d.off += int(val)
+		b := d.data[d.off : d.off+int64(val)]
+		d.off += int64(val)
 		return b, false
 	}
 	// Process indefinite length string chunks.
 	b := []byte{}
 	for !d.foundBreak() {
 		_, _, val = d.getHead()
-		b = append(b, d.data[d.off:d.off+int(val)]...)
-		d.off += int(val)
+		b = append(b, d.data[d.off:d.off+int64(val)]...)
+		d.off += int64(val)
 	}
 	return b, true
 }
@@ -2227,8 +2227,8 @@ func (d *decoder) applyByteStringTextConversion(
 func (d *decoder) parseTextString() ([]byte, error) {
 	_, _, val, indefiniteLength := d.getHeadWithIndefiniteLengthFlag()
 	if !indefiniteLength {
-		b := d.data[d.off : d.off+int(val)]
-		d.off += int(val)
+		b := d.data[d.off : d.off+int64(val)]
+		d.off += int64(val)
 		if d.dm.utf8 == UTF8RejectInvalid && !utf8.Valid(b) {
 			return nil, &SemanticError{"cbor: invalid UTF-8 string"}
 		}
@@ -2238,8 +2238,8 @@ func (d *decoder) parseTextString() ([]byte, error) {
 	b := []byte{}
 	for !d.foundBreak() {
 		_, _, val = d.getHead()
-		x := d.data[d.off : d.off+int(val)]
-		d.off += int(val)
+		x := d.data[d.off : d.off+int64(val)]
+		d.off += int64(val)
 		if d.dm.utf8 == UTF8RejectInvalid && !utf8.Valid(x) {
 			for !d.foundBreak() {
 				d.skip() // Skip remaining chunk on error
@@ -2892,7 +2892,7 @@ func (d *decoder) skip() {
 
 	switch t {
 	case cborTypeByteString, cborTypeTextString:
-		d.off += int(val)
+		d.off += int64(val)
 
 	case cborTypeArray:
 		for i := 0; i < int(val); i++ {
diff --git a/decode_test.go b/decode_test.go
index 5880d73..5b1ae20 100644
--- a/decode_test.go
+++ b/decode_test.go
@@ -325,9 +325,9 @@ var unmarshalTests = []unmarshalTest{
 		wantInterfaceValue: uint64(1000000000000),
 		wantValues: []any{
 			uint64(1000000000000),
-			uint(1000000000000),
+			uint64(1000000000000),
+			int64(1000000000000),
 			int64(1000000000000),
-			int(1000000000000),
 			float32(1000000000000),
 			float64(1000000000000),
 			bigIntOrPanic("1000000000000"),
@@ -355,7 +355,7 @@ var unmarshalTests = []unmarshalTest{
 		wantInterfaceValue: uint64(18446744073709551615),
 		wantValues: []any{
 			uint64(18446744073709551615),
-			uint(18446744073709551615),
+			uint64(18446744073709551615),
 			float32(18446744073709551615),
 			float64(18446744073709551615),
 			bigIntOrPanic("18446744073709551615"),
@@ -5089,12 +5089,12 @@ func TestDecModeInvalidMaxMapPairs(t *testing.T) {
 		{
 			name:         "MaxMapPairs < 16",
 			opts:         DecOptions{MaxMapPairs: 1},
-			wantErrorMsg: "cbor: invalid MaxMapPairs 1 (range is [16, 2147483647])",
+			wantErrorMsg: "cbor: invalid MaxMapPairs 1 (range is [16, 1])",
 		},
 		{
 			name:         "MaxMapPairs > 2147483647",
 			opts:         DecOptions{MaxMapPairs: 2147483648},
-			wantErrorMsg: "cbor: invalid MaxMapPairs 2147483648 (range is [16, 2147483647])",
+			wantErrorMsg: "cbor: invalid MaxMapPairs 2147483648 (range is [16, 2147483648])",
 		},
 	}
 	for _, tc := range testCases {
diff --git a/diagnose.go b/diagnose.go
index 44afb86..a89e9ee 100644
--- a/diagnose.go
+++ b/diagnose.go
@@ -91,11 +91,11 @@ type DiagOptions struct {
 
 	// MaxArrayElements specifies the max number of elements for CBOR arrays.
 	// Default is 128*1024=131072 and it can be set to [16, 2147483647]
-	MaxArrayElements int
+	MaxArrayElements int64
 
 	// MaxMapPairs specifies the max number of key-value pairs for CBOR maps.
 	// Default is 128*1024=131072 and it can be set to [16, 2147483647]
-	MaxMapPairs int
+	MaxMapPairs int64
 }
 
 // DiagMode returns a DiagMode with immutable options.
diff --git a/stream.go b/stream.go
index 7ac6d7d..557f57d 100644
--- a/stream.go
+++ b/stream.go
@@ -15,8 +15,8 @@ type Decoder struct {
 	r         io.Reader
 	d         decoder
 	buf       []byte
-	off       int // next read offset in buf
-	bytesRead int
+	off       int64 // next read offset in buf
+	bytesRead int64
 }
 
 // NewDecoder returns a new decoder that reads and decodes from r using
@@ -56,13 +56,13 @@ func (dec *Decoder) Skip() error {
 		return err
 	}
 
-	dec.off += n
-	dec.bytesRead += n
+	dec.off += int64(n)
+	dec.bytesRead += int64(n)
 	return nil
 }
 
 // NumBytesRead returns the number of bytes read.
-func (dec *Decoder) NumBytesRead() int {
+func (dec *Decoder) NumBytesRead() int64 {
 	return dec.bytesRead
 }
 
@@ -75,13 +75,13 @@ func (dec *Decoder) Buffered() io.Reader {
 // readNext() reads next CBOR data item from Reader to buffer.
 // It returns the size of next CBOR data item.
 // It also returns validation error or read error if any.
-func (dec *Decoder) readNext() (int, error) {
+func (dec *Decoder) readNext() (int64, error) {
 	var readErr error
 	var validErr error
 
 	for {
 		// Process any unread data in dec.buf.
-		if dec.off < len(dec.buf) {
+		if dec.off < int64(len(dec.buf)) {
 			dec.d.reset(dec.buf[dec.off:])
 			off := dec.off // Save offset before data validation
 			validErr = dec.d.wellformed(true, false)
@@ -134,9 +134,9 @@ func (dec *Decoder) readNext() (int, error) {
 func (dec *Decoder) read() (int, error) {
 	// Grow buf if needed.
 	const minRead = 512
-	if cap(dec.buf)-len(dec.buf)+dec.off < minRead {
+	if int64(cap(dec.buf))-int64(len(dec.buf))+dec.off < minRead {
 		oldUnreadBuf := dec.buf[dec.off:]
-		dec.buf = make([]byte, len(dec.buf)-dec.off, 2*cap(dec.buf)+minRead)
+		dec.buf = make([]byte, int64(len(dec.buf))-dec.off, 2*cap(dec.buf)+minRead)
 		dec.overwriteBuf(oldUnreadBuf)
 	}
 
diff --git a/stream_test.go b/stream_test.go
index ae82a0f..de67b12 100644
--- a/stream_test.go
+++ b/stream_test.go
@@ -34,7 +34,7 @@ func TestDecoder(t *testing.T) {
 	for _, tc := range testCases {
 		t.Run(tc.name, func(t *testing.T) {
 			decoder := NewDecoder(tc.reader)
-			bytesRead := 0
+			bytesRead := int64(0)
 			for i := 0; i < 5; i++ {
 				for _, tc := range unmarshalTests {
 					var v any
@@ -48,7 +48,7 @@ func TestDecoder(t *testing.T) {
 					} else if !reflect.DeepEqual(v, tc.wantInterfaceValue) {
 						t.Errorf("Decode() = %v (%T), want %v (%T)", v, v, tc.wantInterfaceValue, tc.wantInterfaceValue)
 					}
-					bytesRead += len(tc.data)
+					bytesRead += int64(len(tc.data))
 					if decoder.NumBytesRead() != bytesRead {
 						t.Errorf("NumBytesRead() = %v, want %v", decoder.NumBytesRead(), bytesRead)
 					}
@@ -91,7 +91,7 @@ func TestDecoderUnmarshalTypeError(t *testing.T) {
 	for _, tc := range testCases {
 		t.Run(tc.name, func(t *testing.T) {
 			decoder := NewDecoder(tc.reader)
-			bytesRead := 0
+			bytesRead := int64(0)
 			for i := 0; i < 5; i++ {
 				for _, tc := range unmarshalTests {
 					for _, typ := range tc.wrongTypes {
@@ -101,7 +101,7 @@ func TestDecoderUnmarshalTypeError(t *testing.T) {
 						} else if _, ok := err.(*UnmarshalTypeError); !ok {
 							t.Errorf("Decode(0x%x) returned wrong error type %T, want UnmarshalTypeError", tc.data, err)
 						}
-						bytesRead += len(tc.data)
+						bytesRead += int64(len(tc.data))
 						if decoder.NumBytesRead() != bytesRead {
 							t.Errorf("NumBytesRead() = %v, want %v", decoder.NumBytesRead(), bytesRead)
 						}
@@ -117,7 +117,7 @@ func TestDecoderUnmarshalTypeError(t *testing.T) {
 						} else if !reflect.DeepEqual(vi, tc.wantInterfaceValue) {
 							t.Errorf("Decode() = %v (%T), want %v (%T)", vi, vi, tc.wantInterfaceValue, tc.wantInterfaceValue)
 						}
-						bytesRead += len(tc.data)
+						bytesRead += int64(len(tc.data))
 						if decoder.NumBytesRead() != bytesRead {
 							t.Errorf("NumBytesRead() = %v, want %v", decoder.NumBytesRead(), bytesRead)
 						}
@@ -159,7 +159,7 @@ func TestDecoderUnexpectedEOFError(t *testing.T) {
 		t.Run(tc.name, func(t *testing.T) {
 
 			decoder := NewDecoder(tc.reader)
-			bytesRead := 0
+			bytesRead := int64(0)
 			for i := 0; i < len(unmarshalTests)-1; i++ {
 				tc := unmarshalTests[i]
 				var v any
@@ -173,7 +173,7 @@ func TestDecoderUnexpectedEOFError(t *testing.T) {
 				} else if !reflect.DeepEqual(v, tc.wantInterfaceValue) {
 					t.Errorf("Decode() = %v (%T), want %v (%T)", v, v, tc.wantInterfaceValue, tc.wantInterfaceValue)
 				}
-				bytesRead += len(tc.data)
+				bytesRead += int64(len(tc.data))
 				if decoder.NumBytesRead() != bytesRead {
 					t.Errorf("NumBytesRead() = %v, want %v", decoder.NumBytesRead(), bytesRead)
 				}
@@ -214,7 +214,7 @@ func TestDecoderReadError(t *testing.T) {
 	for _, tc := range testCases {
 		t.Run(tc.name, func(t *testing.T) {
 			decoder := NewDecoder(tc.reader)
-			bytesRead := 0
+			bytesRead := int64(0)
 			for i := 0; i < len(unmarshalTests)-1; i++ {
 				tc := unmarshalTests[i]
 				var v any
@@ -228,7 +228,7 @@ func TestDecoderReadError(t *testing.T) {
 				} else if !reflect.DeepEqual(v, tc.wantInterfaceValue) {
 					t.Errorf("Decode() = %v (%T), want %v (%T)", v, v, tc.wantInterfaceValue, tc.wantInterfaceValue)
 				}
-				bytesRead += len(tc.data)
+				bytesRead += int64(len(tc.data))
 				if decoder.NumBytesRead() != bytesRead {
 					t.Errorf("NumBytesRead() = %v, want %v", decoder.NumBytesRead(), bytesRead)
 				}
@@ -298,7 +298,7 @@ func TestDecoderRecoverableReadError(t *testing.T) {
 	if !reflect.DeepEqual(v, wantValue) {
 		t.Errorf("Decode() = %v (%T), want %v (%T)", v, v, wantValue, wantValue)
 	}
-	if decoder.NumBytesRead() != len(data) {
+	if decoder.NumBytesRead() != int64(len(data)) {
 		t.Errorf("NumBytesRead() = %v, want %v", decoder.NumBytesRead(), len(data))
 	}
 
@@ -352,13 +352,13 @@ func TestDecoderSkip(t *testing.T) {
 	for _, tc := range testCases {
 		t.Run(tc.name, func(t *testing.T) {
 			decoder := NewDecoder(tc.reader)
-			bytesRead := 0
+			bytesRead := int64(0)
 			for i := 0; i < 5; i++ {
 				for _, tc := range unmarshalTests {
 					if err := decoder.Skip(); err != nil {
 						t.Fatalf("Skip() returned error %v", err)
 					}
-					bytesRead += len(tc.data)
+					bytesRead += int64(len(tc.data))
 					if decoder.NumBytesRead() != bytesRead {
 						t.Errorf("NumBytesRead() = %v, want %v", decoder.NumBytesRead(), bytesRead)
 					}
@@ -394,13 +394,13 @@ func TestDecoderSkipInvalidDataError(t *testing.T) {
 	for _, tc := range testCases {
 		t.Run(tc.name, func(t *testing.T) {
 			decoder := NewDecoder(tc.reader)
-			bytesRead := 0
+			bytesRead := int64(0)
 			for i := 0; i < len(unmarshalTests); i++ {
 				tc := unmarshalTests[i]
 				if err := decoder.Skip(); err != nil {
 					t.Fatalf("Skip() returned error %v", err)
 				}
-				bytesRead += len(tc.data)
+				bytesRead += int64(len(tc.data))
 				if decoder.NumBytesRead() != bytesRead {
 					t.Errorf("NumBytesRead() = %v, want %v", decoder.NumBytesRead(), bytesRead)
 				}
@@ -437,13 +437,13 @@ func TestDecoderSkipUnexpectedEOFError(t *testing.T) {
 	for _, tc := range testCases {
 		t.Run(tc.name, func(t *testing.T) {
 			decoder := NewDecoder(tc.reader)
-			bytesRead := 0
+			bytesRead := int64(0)
 			for i := 0; i < len(unmarshalTests)-1; i++ {
 				tc := unmarshalTests[i]
 				if err := decoder.Skip(); err != nil {
 					t.Fatalf("Skip() returned error %v", err)
 				}
-				bytesRead += len(tc.data)
+				bytesRead += int64(len(tc.data))
 				if decoder.NumBytesRead() != bytesRead {
 					t.Errorf("NumBytesRead() = %v, want %v", decoder.NumBytesRead(), bytesRead)
 				}
@@ -480,13 +480,13 @@ func TestDecoderSkipReadError(t *testing.T) {
 	for _, tc := range testCases {
 		t.Run(tc.name, func(t *testing.T) {
 			decoder := NewDecoder(tc.reader)
-			bytesRead := 0
+			bytesRead := int64(0)
 			for i := 0; i < len(unmarshalTests)-1; i++ {
 				tc := unmarshalTests[i]
 				if err := decoder.Skip(); err != nil {
 					t.Fatalf("Skip() returned error %v", err)
 				}
-				bytesRead += len(tc.data)
+				bytesRead += int64(len(tc.data))
 				if decoder.NumBytesRead() != bytesRead {
 					t.Errorf("NumBytesRead() = %v, want %v", decoder.NumBytesRead(), bytesRead)
 				}
@@ -543,7 +543,7 @@ func TestDecoderSkipRecoverableReadError(t *testing.T) {
 	if err != nil {
 		t.Fatalf("Skip() returned error %v", err)
 	}
-	if decoder.NumBytesRead() != len(data) {
+	if decoder.NumBytesRead() != int64(len(data)) {
 		t.Errorf("NumBytesRead() = %v, want %v", decoder.NumBytesRead(), len(data))
 	}
 
diff --git a/valid.go b/valid.go
index b40793b..7610c53 100644
--- a/valid.go
+++ b/valid.go
@@ -38,20 +38,20 @@ func (e *MaxNestedLevelError) Error() string {
 
 // MaxArrayElementsError indicates exceeded max number of elements for CBOR arrays.
 type MaxArrayElementsError struct {
-	maxArrayElements int
+	maxArrayElements int64
 }
 
 func (e *MaxArrayElementsError) Error() string {
-	return "cbor: exceeded max number of elements " + strconv.Itoa(e.maxArrayElements) + " for CBOR array"
+	return "cbor: exceeded max number of elements " + strconv.FormatInt(e.maxArrayElements, 10) + " for CBOR array"
 }
 
 // MaxMapPairsError indicates exceeded max number of key-value pairs for CBOR maps.
 type MaxMapPairsError struct {
-	maxMapPairs int
+	maxMapPairs int64
 }
 
 func (e *MaxMapPairsError) Error() string {
-	return "cbor: exceeded max number of key-value pairs " + strconv.Itoa(e.maxMapPairs) + " for CBOR map"
+	return "cbor: exceeded max number of key-value pairs " + strconv.FormatInt(e.maxMapPairs, 10) + " for CBOR map"
 }
 
 // IndefiniteLengthError indicates found disallowed indefinite length items.
@@ -73,12 +73,12 @@ func (e *TagsMdError) Error() string {
 
 // ExtraneousDataError indicates found extraneous data following well-formed CBOR data item.
 type ExtraneousDataError struct {
-	numOfBytes int // number of bytes of extraneous data
-	index      int // location of extraneous data
+	numOfBytes int64 // number of bytes of extraneous data
+	index      int64 // location of extraneous data
 }
 
 func (e *ExtraneousDataError) Error() string {
-	return "cbor: " + strconv.Itoa(e.numOfBytes) + " bytes of extraneous data starting at index " + strconv.Itoa(e.index)
+	return "cbor: " + strconv.FormatInt(e.numOfBytes, 10) + " bytes of extraneous data starting at index " + strconv.FormatInt(e.index, 10)
 }
 
 // wellformed checks whether the CBOR data item is well-formed.
@@ -86,13 +86,13 @@ func (e *ExtraneousDataError) Error() string {
 // - use allowExtraData = true when using Decoder.Decode()
 // - use allowExtraData = false when using Unmarshal()
 func (d *decoder) wellformed(allowExtraData bool, checkBuiltinTags bool) error {
-	if len(d.data) == d.off {
+	if int64(len(d.data)) == d.off {
 		return io.EOF
 	}
 	_, err := d.wellformedInternal(0, checkBuiltinTags)
 	if err == nil {
-		if !allowExtraData && d.off != len(d.data) {
-			err = &ExtraneousDataError{len(d.data) - d.off, d.off}
+		if !allowExtraData && d.off != int64(len(d.data)) {
+			err = &ExtraneousDataError{int64(len(d.data)) - d.off, d.off}
 		}
 	}
 	return err
@@ -113,12 +113,12 @@ func (d *decoder) wellformedInternal(depth int, checkBuiltinTags bool) (int, err
 			}
 			return d.wellformedIndefiniteString(t, depth, checkBuiltinTags)
 		}
-		valInt := int(val)
+		valInt := int64(val)
 		if valInt < 0 {
 			// Detect integer overflow
 			return 0, errors.New("cbor: " + t.String() + " length " + strconv.FormatUint(val, 10) + " is too large, causing integer overflow")
 		}
-		if len(d.data)-d.off < valInt { // valInt+off may overflow integer
+		if int64(len(d.data))-d.off < valInt { // valInt+off may overflow integer
 			return 0, io.ErrUnexpectedEOF
 		}
 		d.off += valInt
@@ -136,7 +136,7 @@ func (d *decoder) wellformedInternal(depth int, checkBuiltinTags bool) (int, err
 			return d.wellformedIndefiniteArrayOrMap(t, depth, checkBuiltinTags)
 		}
 
-		valInt := int(val)
+		valInt := int64(val)
 		if valInt < 0 {
 			// Detect integer overflow
 			return 0, errors.New("cbor: " + t.String() + " length " + strconv.FormatUint(val, 10) + " is too large, it would cause integer overflow")
@@ -158,7 +158,7 @@ func (d *decoder) wellformedInternal(depth int, checkBuiltinTags bool) (int, err
 		}
 		maxDepth := depth
 		for j := 0; j < count; j++ {
-			for i := 0; i < valInt; i++ {
+			for i := int64(0); i < valInt; i++ {
 				var dpt int
 				if dpt, err = d.wellformedInternal(depth, checkBuiltinTags); err != nil {
 					return 0, err
@@ -179,7 +179,7 @@ func (d *decoder) wellformedInternal(depth int, checkBuiltinTags bool) (int, err
 
 		// Scan nested tag numbers to avoid recursion.
 		for {
-			if len(d.data) == d.off { // Tag number must be followed by tag content.
+			if int64(len(d.data)) == d.off { // Tag number must be followed by tag content.
 				return 0, io.ErrUnexpectedEOF
 			}
 			if checkBuiltinTags {
@@ -216,7 +216,7 @@ func (d *decoder) wellformedInternal(depth int, checkBuiltinTags bool) (int, err
 func (d *decoder) wellformedIndefiniteString(t cborType, depth int, checkBuiltinTags bool) (int, error) {
 	var err error
 	for {
-		if len(d.data) == d.off {
+		if int64(len(d.data)) == d.off {
 			return 0, io.ErrUnexpectedEOF
 		}
 		if isBreakFlag(d.data[d.off]) {
@@ -242,9 +242,9 @@ func (d *decoder) wellformedIndefiniteString(t cborType, depth int, checkBuiltin
 func (d *decoder) wellformedIndefiniteArrayOrMap(t cborType, depth int, checkBuiltinTags bool) (int, error) {
 	var err error
 	maxDepth := depth
-	i := 0
+	i := int64(0)
 	for {
-		if len(d.data) == d.off {
+		if int64(len(d.data)) == d.off {
 			return 0, io.ErrUnexpectedEOF
 		}
 		if isBreakFlag(d.data[d.off]) {
@@ -291,7 +291,7 @@ func (d *decoder) wellformedHeadWithIndefiniteLengthFlag() (
 }
 
 func (d *decoder) wellformedHead() (t cborType, ai byte, val uint64, err error) {
-	dataLen := len(d.data) - d.off
+	dataLen := int64(len(d.data)) - d.off
 	if dataLen == 0 {
 		return 0, 0, 0, io.ErrUnexpectedEOF
 	}
diff --git a/valid_test.go b/valid_test.go
index f4637b8..d6caefd 100644
--- a/valid_test.go
+++ b/valid_test.go
@@ -29,8 +29,8 @@ func TestValidExtraneousData(t *testing.T) {
 	testCases := []struct {
 		name                     string
 		data                     []byte
-		extraneousDataNumOfBytes int
-		extraneousDataIndex      int
+		extraneousDataNumOfBytes int64
+		extraneousDataIndex      int64
 	}{
 		{"two numbers", []byte{0x00, 0x01}, 1, 1},                                // 0, 1
 		{"bytestring and int", []byte{0x44, 0x01, 0x02, 0x03, 0x04, 0x00}, 1, 5}, // h'01020304', 0
