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

server: fix binary numeric type overflow #6922

Merged
merged 8 commits into from
Jul 9, 2018
Merged

Conversation

jackysp
Copy link
Member

@jackysp jackysp commented Jun 27, 2018

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

@@ -273,9 +273,9 @@ func parseStmtArgs(args []interface{}, boundParams [][]byte, nullBitmap, paramTy
}

if isUnsigned {
Copy link
Member Author

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]))
Copy link
Member Author

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.

@jackysp
Copy link
Member Author

jackysp commented Jun 27, 2018

Maybe unit tests from MySQL official jdbc are usefully to cover the binary type code.

@jackysp
Copy link
Member Author

jackysp commented Jun 27, 2018

/run-all-tests

Copy link
Member

@shenli shenli left a 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])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use uint8?

@shenli
Copy link
Member

shenli commented Jun 28, 2018

Where is the integration test?

@coocood
Copy link
Member

coocood commented Jun 28, 2018

LGTM

@coocood coocood added the status/LGT1 Indicates that a PR has LGTM 1. label Jun 28, 2018
Copy link
Contributor

@lysu lysu left a 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~?

@jackysp
Copy link
Member Author

jackysp commented Jun 28, 2018

Unit test cases added. But still DNM. @shenli @lysu

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/uint16(valU16)/valU16?

@@ -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)
Copy link
Contributor

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]))
Copy link
Contributor

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?

Copy link
Member Author

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.

  1. There's no signed or unsigned float.
  2. jdbc test cases in tidb-test will cover this. The unit test is not suitable for this case.

@jackysp
Copy link
Member Author

jackysp commented Jul 9, 2018

/run-common-test tidb-test=pr/564

@jackysp jackysp removed the status/DNM label Jul 9, 2018
@jackysp
Copy link
Member Author

jackysp commented Jul 9, 2018

PTAL @zimulala

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zimulala zimulala added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 9, 2018
@jackysp jackysp merged commit eeeb092 into pingcap:master Jul 9, 2018
@jackysp jackysp deleted the binary_int branch July 9, 2018 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/mysql-protocol status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants