-
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
invalid memory address or nil pointer dereference in expression.newFunctionImpl
->expression.BuildCastFunctionWithCheck
#55886
Comments
expression.BuildCastFunction
->expression.BuildCastFunctionWithCheck
expression.newFunctionImpl
->expression.BuildCastFunctionWithCheck
Hi @ycybfhb I can not reproduce the issue using the provided schema and sql, do you use some special settings in your cluster? |
Hello, please run this before execution. (This is the default behaviour of MySQL ODBC ANSI driver) set collation_connection='latin1_bin'; |
Thanks, I can reproduce it now. |
The root cause of this issue is there is tidb/pkg/expression/expression.go Line 994 in f0ac8f4
it uses NewFunctionInternal to construct the new function, and inside NewFunctionInternal , it will just ignore the error and return nil instead.I would like label this issue as a planner bug because the callstack is from Optimize , and there is no error handle logical in the whole ConvertOuterToInnerJoin process. |
@windtalker : what is the expected behaviour of the expression logic when there is a mix of collation? Is there a graceful way of returning to the caller? I do not see a way of fixing this from the consumer side (optimizer). One way is to make expression.EvaluateExprWithNull return result and a boolean for the success/failure of the evaluation. |
I think if there is a mix of collation, TiDB will try to call tidb/pkg/expression/scalar_function.go Lines 327 to 333 in 738adb9
evaluateExprWithNullInNullRejectCheck should use NewFunction and handle the error explicitly.
|
@windtalker OK and looked at this but the error is actally a panice and not an error. In any case, the consumer is an optimization which is OK if the check is true (nullreject) or false (not null reject or unknown which covers error). Seems the fix need to be applied in NewFunctionInternal (may be use NewFunction or similiar logic) to return result and bool for success/failure. Do you agree and if so who can fix it? The other way to fix it is to make the consumer not make the call for such cases which is hard and may cause false positives. |
We can bring back the old logic of returning an bool based on context (optimization path) and keep the rest the same. |
Thanks @windtalker for taking care of the fix as we discussed. The expression logic returns an error to the caller if it is an optimization "ctx.IsInNullRejectCheck()" |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
SQL to init database
SQL that causes error
2. What did you expect to see? (Required)
Expect no crashes
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
We are the BASS team from the School of Cyber Science and Technology at Beihang University. Our main focus is on system software security, operating systems, and program analysis research, as well as the development of automated program testing frameworks for detecting software defects. Using our self-developed database vulnerability testing tool, we have identified the above-mentioned vulnerabilities in TiDB that may lead to database crashes.
The text was updated successfully, but these errors were encountered: