parser
parser copied to clipboard
SQLMode should be int64 or uint64; similarly for lengthAndDecimal fields
Bug Report
In pingcap/parser/mysql/const.go, the type:
type SQLMode int
but it has too many bit definitions to fit in 32 bits. It should be int64 or uint64
Similarly, in pingcap/parser/mysql/util.go
type lengthAndDecimal struct {
length int
decimal int
}
the int fields should be int64 or uint64 because the TypeLongBlob and TypeJSON have lengths too large for 32-bit.
Please answer these questions before submitting your issue. Thanks!
- What did you do?
Create a simple
main.gothat references this package:
package main
import (
"fmt"
"github.com/pingcap/parser/mysql"
)
func main() {
var foo mysql.SQLMode
fmt.Println(foo)
}
Either build it on a 32-bit host, or cross-build it for 32-bit with:
$ GOOS=linux GOARCH=386 go build main.go
-
What did you expect to see? The build should pass.
-
What did you see instead?
$ GOOS=linux GOARCH=386 go build main.go
/go/src/github.com/pingcap/parser/mysql/const.go:585:2: constant 2147483648 overflows SQLMode
/go/src/github.com/pingcap/parser/mysql/const.go:586:2: constant 4294967296 overflows SQLMode
/go/src/github.com/pingcap/parser/mysql/const.go:587:2: constant 8589934592 overflows SQLMode
/go/src/github.com/pingcap/parser/mysql/util.go:44:19: constant 4294967295 overflows int
/go/src/github.com/pingcap/parser/mysql/util.go:45:19: constant 4294967295 overflows int
Building for 64-bit will work since int is architecture-specific, but the code should be able to build/run regardless of the architecture selected.
$ GOOS=linux GOARCH=amd64 go build main.go
passes.
- What version of TiDB SQL Parser are you using? pingcap/parser is at b3d8b232cff88a9e1f612b1e91a18b6331f3024b (master as of June 19th, 2019) tidb isn't included as it wasn't necessary due to vendor pruning.
Similar to the collation ID risk :(
https://github.com/pingcap/parser/blob/master/mysql/charset.go#L126