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

patch upstream pr 4660 (Fix panic in vtgate when MakeRowTrusted gets bad result) #21

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions go/sqltypes/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,14 @@ func hashCodeForRow(val []Value) string {
// Every place this function is called, a comment is needed that explains
// why it's justified.
func MakeRowTrusted(fields []*querypb.Field, row *querypb.Row) []Value {
sqlRow := make([]Value, len(row.Lengths))
sqlRow := make([]Value, len(fields))
var offset int64
for i, length := range row.Lengths {
for i, fld := range fields {
length := row.Lengths[i]
if length < 0 {
continue
}
sqlRow[i] = MakeTrusted(fields[i].Type, row.Values[offset:offset+length])
sqlRow[i] = MakeTrusted(fld.Type, row.Values[offset:offset+length])
offset += length
}
return sqlRow
Expand Down
55 changes: 55 additions & 0 deletions go/sqltypes/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,61 @@ import (
querypb "vitess.io/vitess/go/vt/proto/query"
)

func TestMakeRowTrusted(t *testing.T) {
fields := MakeTestFields(
"some_int|some_text|another_int",
"int8|varchar|int8",
)

values := []byte{}
hw := []byte("hello, world")
values = append(values, hw...)
values = append(values, byte(42))

row := &querypb.Row{
Lengths: []int64{-1, int64(len(hw)), 1},
Values: values,
}

want := []Value{
MakeTrusted(querypb.Type_NULL_TYPE, nil),
MakeTrusted(querypb.Type_VARCHAR, []byte("hello, world")),
MakeTrusted(querypb.Type_INT8, []byte{byte(42)}),
}

result := MakeRowTrusted(fields, row)
if !reflect.DeepEqual(result, want) {
t.Errorf("MakeRowTrusted:\ngot: %#v\nwant: %#v", result, want)
}
}

func TestMakeRowTrustedDoesNotPanicOnNewColumns(t *testing.T) {
fields := MakeTestFields(
"some_int|some_text",
"int8|varchar",
)

values := []byte{byte(123)}
hw := []byte("hello, world")
values = append(values, hw...)
values = append(values, byte(42))

row := &querypb.Row{
Lengths: []int64{1, int64(len(hw)), 1},
Values: values,
}

want := []Value{
MakeTrusted(querypb.Type_INT8, []byte{byte(123)}),
MakeTrusted(querypb.Type_VARCHAR, []byte("hello, world")),
}

result := MakeRowTrusted(fields, row)
if !reflect.DeepEqual(result, want) {
t.Errorf("MakeRowTrusted:\ngot: %#v\nwant: %#v", result, want)
}
}

func TestRepair(t *testing.T) {
fields := []*querypb.Field{{
Type: Int64,
Expand Down