diff --git a/cbor/tags.go b/cbor/tags.go index 5bf90bf8..cf9af612 100644 --- a/cbor/tags.go +++ b/cbor/tags.go @@ -93,11 +93,19 @@ type Rat struct { } func (r *Rat) UnmarshalCBOR(cborData []byte) error { - tmpRat := []int64{} + tmpRat := []uint64{} if _, err := Decode(cborData, &tmpRat); err != nil { return err } - r.Rat = big.NewRat(tmpRat[0], tmpRat[1]) + // Convert numerator and denominator to big.Int + // It's necessary to do this to support num/denom larger than int64 (up to uint64) + tmpNum := new(big.Int) + tmpNum.SetUint64(tmpRat[0]) + tmpDenom := new(big.Int) + tmpDenom.SetUint64(tmpRat[1]) + // Create new big.Rat with num/denom set to big.Int values above + r.Rat = new(big.Rat) + r.Rat.SetFrac(tmpNum, tmpDenom) return nil } diff --git a/cbor/tags_test.go b/cbor/tags_test.go index b8d26aeb..341237c5 100644 --- a/cbor/tags_test.go +++ b/cbor/tags_test.go @@ -54,6 +54,15 @@ var tagsTestDefs = []struct { }, ), }, + { + cborHex: "d81e821b80000000000000011b8ac7230489e80000", + object: cbor.Rat{ + Rat: new(big.Rat).SetFrac( + new(big.Int).SetUint64(9223372036854775809), + new(big.Int).SetUint64(10000000000000000000), + ), + }, + }, } func TestTagsDecode(t *testing.T) {