Skip to content

Commit

Permalink
Avoid modifying input buffer while decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Feb 20, 2025
1 parent 6817814 commit 74f726b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/codec/encodings/binary/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,16 @@ func (littleBigInt) serializeUnsigned(size int, i *big.Int) ([]byte, error) {
}

func (littleBigInt) deserializeSigned(size int, b []byte) *big.Int {
slices.Reverse(b)
bi, _ := bigbigendian.DeserializeSigned(size, b)
r := make([]byte, len(b))
copy(r, b)
slices.Reverse(r)
bi, _ := bigbigendian.DeserializeSigned(size, r)
return bi
}

func (littleBigInt) deserializeUnsigned(_ int, b []byte) *big.Int {
slices.Reverse(b)
return new(big.Int).SetBytes(b)
r := make([]byte, len(b))
copy(r, b)
slices.Reverse(r)
return new(big.Int).SetBytes(r)
}

0 comments on commit 74f726b

Please sign in to comment.