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

Null tuple cause panic #1343

Closed
supar opened this issue Sep 4, 2019 · 0 comments · Fixed by #1424
Closed

Null tuple cause panic #1343

supar opened this issue Sep 4, 2019 · 0 comments · Fixed by #1424

Comments

@supar
Copy link

supar commented Sep 4, 2019

Please answer these questions before submitting your issue. Thanks!

What version of Cassandra are you using?

cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4

What version of Gocql are you using?

f6df828

What did you do?

CREATE TABLE products (
            id timeuuid PRIMARY KEY,
            name text,
            category frozen<tuple<timeuuid, varchar>>
 );

INSERT INTO products(id, name) VALUES (cb403e20-ce63-11e9-b49a-d99f577eb025, 'Without category');

SELECT * FROM products;

 id                                   | name       | category
--------------------------------------+------------+----------
 cb403e20-ce63-11e9-b49a-d99f577eb025 | Without category |     null

What did you expect to see?

no panic

What did you see instead?

http: panic serving 172.17.0.1:57798: runtime error: index out of range
goroutine 61 [running]:
net/http.(*conn).serve.func1(0xc000348140)
	/usr/local/go/src/net/http/server.go:1769 +0x139
panic(0xa2b360, 0x11f5160)
	/usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/gocql/gocql.readInt(...)
	/go/src/github.com/gocql/gocql/frame.go:322
github.com/gocql/gocql.readBytes(...)
	/go/src/github.com/gocql/gocql/marshal.go:1788
github.com/gocql/gocql.unmarshalTuple(0xbcfd20, 0xc000372540, 0x0, 0x0, 0x0, 0x9e5280, 0xc000380420, 0x0, 0x0)
	/go/src/github.com/gocql/gocql/marshal.go:1810 +0x11a7
github.com/gocql/gocql.Unmarshal(0xbcfd20, 0xc000372540, 0x0, 0x0, 0x0, 0x9e5280, 0xc000380420, 0xc0000c6d68, 0x69a3c5)
	/go/src/github.com/gocql/gocql/marshal.go:162 +0xdaa
github.com/gocql/gocql.scanColumn(0x0, 0x0, 0x0, 0xc000024ff0, 0x3, 0xc000024ff8, 0x8, 0xc000025028, 0x8, 0xbcfd20, ...)
	/go/src/github.com/gocql/gocql/session.go:1292 +0x1b3
github.com/gocql/gocql.(*Iter).Scan(0xc0002dcab0, 0xc00031e1c0, 0x7, 0x7, 0xc00031e1c0)
	/go/src/github.com/gocql/gocql/session.go:1397 +0x2e5

It happens while readInt function retrieves size from empty []byte

frame.go

func readInt(p []byte) int32 {
    return int32(p[0])<<24 | int32(p[1])<<16 | int32(p[2])<<8 | int32(p[3])
}

marshal.go

func readBytes(p []byte) ([]byte, []byte) {
    // TODO: really should use a framer
    size := readInt(p)
    p = p[4:]
    if size < 0 {
        return nil, p
    }
    return p[:size], p[size:]
}

There is comment on

// currently only support unmarshal into a list of values, this makes it possible
// to support tuples without changing the query API. In the future this can be extend
// to allow unmarshalling into custom tuple types.
func unmarshalTuple(info TypeInfo, data []byte, value interface{}) error {

Maybe this means that field should be category list<frozen<tuple<timeuuid, varchar>>>, but it's not panic case

dahankzter added a commit to dahankzter/gocql that referenced this issue Apr 2, 2020
In case the tuple value has never been written the unmarshalling
used to panic. This is now handled by inspecting the data from the
database and if it is missing (nil) it will set the tuple value to
the corresponding default value.

Fixes: apache#1343
dahankzter added a commit to scylladb/gocql that referenced this issue Apr 3, 2020
In case the tuple value has never been written the unmarshalling
used to panic. This is now handled by inspecting the data from the
database and if it is missing (nil) it will set the tuple value to
the corresponding default value.

Fixes: apache#1343
Zariel pushed a commit that referenced this issue Apr 10, 2020
* tuples: correct unmarshalling of unset tuple values

In case the tuple value has never been written the unmarshalling
used to panic. This is now handled by inspecting the data from the
database and if it is missing (nil) it will set the tuple value to
the corresponding default value.

Fixes: #1343

* tuples: scan target vars reset of unset tuple values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant