-
Notifications
You must be signed in to change notification settings - Fork 473
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
fix(json): int64 overflow in JSON numop #2340
fix(json): int64 overflow in JSON numop #2340
Conversation
Thank you for your great finding. |
src/types/redis_json.cc
Outdated
if (!number_res.GetValue().value.is_int64() && !number_res.GetValue().value.is_double()) { | ||
return rocksdb::Status::InvalidArgument("number out of range"); | ||
} |
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 it can be fixed in the JsonValue::NumOp. Here we can only fix for value
, not the number inside the current json.
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.
Thank you. Summarized all the situations to see if there were any omissions
Quality Gate passedIssues Measures |
…ocks into fix-remote-over-range
…sss/kvrocks into fix-remote-over-range
src/common/bit_util.h
Outdated
inline bool Int64OperationOverFlow(int64_t a, int64_t b, int64_t result, uint8_t operation) { | ||
if (operation == 1) { | ||
return __builtin_add_overflow(a, b, &result); | ||
} else { | ||
return __builtin_mul_overflow(a, b, &result); | ||
} | ||
} |
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.
This function looks very weird. What's operation
? What's 1
here? Why mul
is executed if operation
is not 1
?
Please remove it.
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.
Also, this function is totally wrong since the result is passed by 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.
Please just add a catch block. Try not to add any meaningless weird code.
Simple catch doesn't seem to work, some overflow cases can return results that don't meet expectations without throwing exceptions |
It can be actually well defined. It follows the two's complement. So generally we can leave it as is until we make a big number implementation available. |
What do you mean by directly adding a catch (const jsoncons:: json_runtime_error<std:: runtime_error>e){ |
Yeah, just preventing kvrocks from crash is enough. |
Sorry I looked into this problem a little bit, and seems it's a design issue inside the NumOp method. I opened a PR to address it (#2345). But anyway thank you very much for your great finding and effort. |
You have made the same changes to the visual and redis stack processing, and have learned a lot |
Json_val. NumOp only considers cases where the value of the double type is out of bounds, and does not consider cases where the int64 type is out of bounds. If the int64 type is out of bounds, it will cause the lambda function to exit abnormally and not catch. This exception will cause the kvrocks to crash