dolt icon indicating copy to clipboard operation
dolt copied to clipboard

TestDecodeOverflows fails on m1 macs

Open druvv opened this issue 2 years ago • 0 comments

fails here:

func TestDecodeOverflows(tt *testing.T) {
	t := func(p interface{}, n float64, ts string) {
		assertDecodeErrorMessage(tt, types.Float(n), p, fmt.Sprintf("Cannot unmarshal from: Float to: %s details: (%g does not fit in %s)", ts, n, ts))
	}

	var ui8 uint8
	t(&ui8, 256, "uint8")
	t(&ui8, -1, "uint8") <-----------

Passes on m1 mac, but fails on others:

func Test2(t *testing.T) {
	v := float64(-1)
	require.Equal(t, uint64(0), uint64(v))
}

In uintDecoder we cast a negative float to uint64. The result u, contains a value 0 on m1 macs which passes the overflow check:

func uintDecoder(ctx context.Context, nbf *types.NomsBinFormat, v types.Value, rv reflect.Value) error {
	if n, ok := v.(types.Float); ok {
		u := uint64(n) <-----------------------
		if rv.OverflowUint(u) {
			return overflowError(nbf, n, rv.Type())
		}
		rv.SetUint(u)
		return nil
	}

	// types.Uint is currently encoded as types.Float during marshalling
	// the block below exists to prepare for a compatibility breaking change
	// todo: update comment after breaking change is made
	if n, ok := v.(types.Uint); ok {
		rv.SetUint(uint64(n))
		return nil
	}

	return &UnmarshalTypeMismatchError{v, rv.Type(), "", nbf}
}

druvv avatar Mar 25 '22 21:03 druvv