-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
server: fix binary numeric type overflow #6922
Conversation
@@ -273,9 +273,9 @@ func parseStmtArgs(args []interface{}, boundParams [][]byte, nullBitmap, paramTy | |||
} | |||
|
|||
if isUnsigned { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think binary int does not have an unsigned flag.
@@ -329,7 +329,7 @@ func parseStmtArgs(args []interface{}, boundParams [][]byte, nullBitmap, paramTy | |||
return | |||
} | |||
|
|||
args[i] = float64(math.Float32frombits(binary.LittleEndian.Uint32(paramValues[pos : pos+4]))) | |||
args[i] = math.Float32frombits(binary.LittleEndian.Uint32(paramValues[pos : pos+4])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know why there is a cast here, either.
Maybe unit tests from MySQL official jdbc are usefully to cover the binary type code. |
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which line is the root cause of the overflow?
@@ -273,9 +273,9 @@ func parseStmtArgs(args []interface{}, boundParams [][]byte, nullBitmap, paramTy | |||
} | |||
|
|||
if isUnsigned { | |||
args[i] = uint64(paramValues[pos]) | |||
args[i] = uint8(paramValues[pos]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use uint8?
Where is the integration test? |
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better add a overflow case in server/conn_stmt_test.go:TestParseStmtArgs()
to help regression~?
server/conn_stmt.go
Outdated
@@ -288,9 +288,9 @@ func parseStmtArgs(args []interface{}, boundParams [][]byte, nullBitmap, paramTy | |||
} | |||
valU16 := binary.LittleEndian.Uint16(paramValues[pos : pos+2]) | |||
if isUnsigned { | |||
args[i] = uint64(valU16) | |||
args[i] = uint16(valU16) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/uint16(valU16)/valU16?
server/conn_stmt.go
Outdated
@@ -302,9 +302,9 @@ func parseStmtArgs(args []interface{}, boundParams [][]byte, nullBitmap, paramTy | |||
} | |||
valU32 := binary.LittleEndian.Uint32(paramValues[pos : pos+4]) | |||
if isUnsigned { | |||
args[i] = uint64(valU32) | |||
args[i] = uint32(valU32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/uint32(valU32)/valU32?
@@ -329,7 +329,7 @@ func parseStmtArgs(args []interface{}, boundParams [][]byte, nullBitmap, paramTy | |||
return | |||
} | |||
|
|||
args[i] = float64(math.Float32frombits(binary.LittleEndian.Uint32(paramValues[pos : pos+4]))) | |||
args[i] = math.Float32frombits(binary.LittleEndian.Uint32(paramValues[pos : pos+4])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add a test case for this type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to do it.
- There's no signed or unsigned float.
- jdbc test cases in tidb-test will cover this. The unit test is not suitable for this case.
/run-common-test tidb-test=pr/564 |
PTAL @zimulala |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What have you changed? (mandatory)
When using jdbc to setInt(-1) to an int type column, it will cause an overflow error.
What are the type of the changes (mandatory)?
Bug fix.
How has this PR been tested (mandatory)?
Integration tests.
PTAL @coocood @lysu