-
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
types: fix uint64 overflow bug in ConvertJSONToFloat
#11355
Conversation
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #11355 +/- ##
===============================================
- Coverage 81.5114% 81.277% -0.2345%
===============================================
Files 423 423
Lines 91278 90210 -1068
===============================================
- Hits 74402 73320 -1082
- Misses 11571 11590 +19
+ Partials 5305 5300 -5 |
Codecov Report
@@ Coverage Diff @@
## master #11355 +/- ##
===========================================
Coverage 81.4748% 81.4748%
===========================================
Files 424 424
Lines 91249 91249
===========================================
Hits 74345 74345
Misses 11583 11583
Partials 5321 5321 |
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.
.
@@ -553,8 +553,7 @@ func ConvertJSONToFloat(sc *stmtctx.StatementContext, j json.BinaryJSON) (float6 | |||
case json.TypeCodeInt64: | |||
return float64(j.GetInt64()), nil | |||
case json.TypeCodeUint64: | |||
u, err := ConvertIntToUint(sc, j.GetInt64(), IntergerUnsignedUpperBound(mysql.TypeLonglong), mysql.TypeLonglong) |
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.
Should we consider ShouldClipToZero
?
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.
I think we need to consider this.
we extract a uint from the json, it must not < 0.
// GetInt64 gets the int64 value.
func (bj BinaryJSON) GetInt64() int64 {
return int64(endian.Uint64(bj.Value))
}
// GetUint64 gets the uint64 value.
func (bj BinaryJSON) GetUint64() uint64 {
return endian.Uint64(bj.Value)
}
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.
need or needn't?
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.
needn't
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.
Could you please add some integration tests in integration_test.go?
ConvertJSONToFloat
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
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
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
result = tk.MustQuery(`select cast(20170118.999 as datetime);`) | ||
result.Check(testkit.Rows("2017-01-18 00:00:00")) | ||
|
||
tk.MustExec(`create table tb5(a bigint(64) unsigned, b double);`) |
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 not directly create a json column?
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.
If directly creat json, then I can not get a uint field(#11386 (comment)).
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.
how about casting '9223372036854775808' to uint then cast to json?
/run-all-tests |
Ready to merge! |
cherry pick to release-2.1 failed |
cherry pick to release-3.0 in PR #11433 |
All tests passed, auto merged by Bot
All tests passed, auto merged by Bot
What problem does this PR solve?
In the origin version
ConvertIntToUint(sc, j.GetInt64(), IntergerUnsignedUpperBound(mysql.TypeLonglong), mysql.TypeLonglong)
, whenj.GetInt64()
return neg number such as1<<63
, thenConvertIntToUint
may treat it as overflow, this is a bug.What is changed and how it works?
Replace
j.GetInt64
byj.GetUint64
Check List
Tests
Related changes