Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marshal, unmarshal. For many cql types unmarshaling data that have bigger len than cql type, do not return an error. #246

Open
illia-li opened this issue Aug 27, 2024 · 0 comments
Assignees
Labels

Comments

@illia-li
Copy link

illia-li commented Aug 27, 2024

Currently the functions for Unmarshaling many cql types, do not return an error, then the data has a longer length than the cql type.
Type list: TypeBoolean, TypeTinyInt, TypeSmallInt, TypeInt, TypeBigInt, TypeCounter, TypeDouble, TypeFloat, TypeInet, TypeTime, TypeDate, TypeTimestamp, TypeVarint, TypeDuration.

Testcode:

func TestDataOverflow(t *testing.T) {
	types := []TypeInfo{
		NativeType{proto: 2, typ: TypeBoolean},
		NativeType{proto: 2, typ: TypeTinyInt},
		NativeType{proto: 2, typ: TypeSmallInt},
		NativeType{proto: 2, typ: TypeInt},
		NativeType{proto: 2, typ: TypeBigInt},
		NativeType{proto: 2, typ: TypeCounter},
		NativeType{proto: 2, typ: TypeDouble},
		NativeType{proto: 2, typ: TypeFloat},
		NativeType{proto: 2, typ: TypeInet},
		NativeType{proto: 2, typ: TypeTime},
		NativeType{proto: 2, typ: TypeDate},
		NativeType{proto: 2, typ: TypeTimestamp},
		NativeType{proto: 2, typ: TypeVarint},

		NativeType{proto: 2, typ: TypeDuration},
	}

	noErrs := make([]string, 0)
	for _, tp := range types {
		data := []byte{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 252}
		val := tp.New()
		if err := Unmarshal(tp, data, val); err != nil {
			continue
		}
		if val != nil {
			val = dereference(val)
		}
		noErrs = append(noErrs, fmt.Sprintf("type:<%s> - value: <%v>", tp.Type().String(), val))
	}
	t.Errorf("\nOut of %d test cases, %d cases without errors:\n%s", len(types), len(noErrs), strings.Join(noErrs, "\n"))
}

Output:

=== RUN   TestDataOverflow
    marshal_0_all_test.go:129: 
        Out of 14 test cases, 14 cases without errors:
        type:<boolean> - value: <true>
        type:<tinyint> - value: <0>
        type:<smallint> - value: <0>
        type:<int> - value: <0>
        type:<bigint> - value: <0>
        type:<counter> - value: <0>
        type:<double> - value: <0>
        type:<float> - value: <0>
        type:<inet> - value: <?01000000000100000000fffffffffffffffc>
        type:<time> - value: <0s>
        type:<date> - value: <-5831707-12-06 00:00:00 +0000 UTC>
        type:<timestamp> - value: <1970-01-01 00:00:00 +0000 UTC>
        type:<varint> - value: <87112285931839474809156610584199915634684>
        type:<duration> - value: <{-1 0 0}>
--- FAIL: TestDataOverflow (0.00s)
@illia-li illia-li changed the title Marshal, unmarshal. For many cql types marshaling data that have bigger len than cql type, do not return an error. Marshal, unmarshal. For many cql types marshaling data that have bigger len than cql type, do not return an error. Aug 27, 2024
@dkropachev dkropachev added the bug label Aug 27, 2024
@dkropachev dkropachev self-assigned this Aug 27, 2024
@illia-li illia-li changed the title Marshal, unmarshal. For many cql types marshaling data that have bigger len than cql type, do not return an error. Marshal, unmarshal. For many cql types marshaling data that have bigger len than cql type, do not return an error. Aug 29, 2024
@illia-li illia-li changed the title Marshal, unmarshal. For many cql types marshaling data that have bigger len than cql type, do not return an error. Marshal, unmarshal. For many cql types unmarshaling data that have bigger len than cql type, do not return an error. Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants