Skip to content

Conversation

enigma-hh
Copy link
Contributor

@enigma-hh enigma-hh commented Jun 10, 2025

…t converted to larger type #{564}

What problem were solved in this pull request?

In bplus_tree.cpp, there was a risk of integer overflow in the multiplication operation this->size() * _item_size(). The multiplication was initially performed using the int type . Before being converted to a larger type ( size_type), an overflow might occur. This could lead to incorrect parameters being passed to subsequent operations like node_remove_items, potentially causing issues such as memory over - boundaries and logical errors.
Issue Number: close #564

Problem:

What is changed and how it works?

Changed Code: In the LeafIndexNodeHandler::move_to method and LeafIndexNodeHandler::append method the parameters of the multiplication operation are converted for type safety.
1.LeafIndexNodeHandler::move_to method:
From:

RC rc = mtr_.logger().node_remove_items(*this, 0, span<const char>(__item_at(0), this->size() * item_size()), this->size());

To:

RC rc = mtr_.logger().node_remove_items(*this, 0, span<const char>(__item_at(0), static_cast<size_t>(this->size()) * static_cast<size_t>(item_size())), this->size());

2.LeafIndexNodeHandler::append method:
From:

RC rc = mtr_.logger().node_insert_items(*this, size(), span<const char>(items, num * item_size()), num);

To:

RC rc = mtr_.logger().node_insert_items(*this, size(), span<const char>(items, static_cast<size_t>(num) * static_cast<size_t>(item_size())), num);

Other information

@CLAassistant
Copy link

CLAassistant commented Jun 10, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@nautaa nautaa left a comment

Choose a reason for hiding this comment

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

directly use static_cast is better?

enigma-hh and others added 2 commits June 11, 2025 14:48
@enigma-hh enigma-hh requested a review from nautaa June 12, 2025 09:16
Copy link
Member

@nautaa nautaa left a comment

Choose a reason for hiding this comment

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

LGTM

@nautaa nautaa merged commit 6f469d4 into oceanbase:main Jun 12, 2025
15 checks passed
@nautaa
Copy link
Member

nautaa commented Jun 12, 2025

Thanks for your contribution, feel free to participate in more contributions if you are interested.

@enigma-hh enigma-hh deleted the {issue_564} branch June 12, 2025 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]Fix code scanning alert - Multiplication result converted to larger type
3 participants