parser icon indicating copy to clipboard operation
parser copied to clipboard

SQLMode should be int64 or uint64; similarly for lengthAndDecimal fields

Open somersf opened this issue 6 years ago • 1 comments

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!

  1. What did you do? Create a simple main.go that 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
  1. What did you expect to see? The build should pass.

  2. 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.

  1. 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.

somersf avatar Jun 20 '19 15:06 somersf

Similar to the collation ID risk :(

https://github.com/pingcap/parser/blob/master/mysql/charset.go#L126

bb7133 avatar Oct 29 '20 14:10 bb7133