[#356] refs: Handle uint32 overflow in `SubnetID` text format

Clarify the bit size limit in `SubnetID.UnmarshalText` method. Cover
overflow case in unit test.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
remotes/KirillovDenis/master
Leonard Lyubich 2021-11-22 12:34:09 +03:00 committed by LeL
parent 4560e447e1
commit dc292864aa
2 changed files with 13 additions and 1 deletions

View File

@ -199,7 +199,9 @@ func (s *SubnetID) MarshalText() ([]byte, error) {
}
// UnmarshalText decodes SubnetID from the text according to NeoFS API V2 protocol:
// should be base-10 integer string format.
// should be base-10 integer string format with bitsize = 32.
//
// Returns strconv.ErrRange if integer overflows uint32.
//
// Must not be called on nil.
//

View File

@ -1,6 +1,7 @@
package refs_test
import (
"math"
"strconv"
"testing"
@ -47,4 +48,13 @@ func TestSubnetID_UnmarshalText(t *testing.T) {
require.NoError(t, err)
require.EqualValues(t, val, id.GetValue())
t.Run("uint32 overflow", func(t *testing.T) {
txt := strconv.FormatUint(math.MaxUint32+1, 10)
var id refs.SubnetID
err := id.UnmarshalText([]byte(txt))
require.ErrorIs(t, err, strconv.ErrRange)
})
}