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

[Bug] Fix bug that memory copy may overflow in MemIndex::load_segment #4458

Merged
merged 2 commits into from
Aug 30, 2020

Conversation

acelyc111
Copy link
Member

@acelyc111 acelyc111 commented Aug 26, 2020

Proposed changes

Segment index file content is not set as 0 when it is constructed in write procedure, so when load index from this file, and meet a null VARCHAR cell, the null field of this cell is 0, but the length field which is not initialized maybe a large random number, then memory copy may cause overflow.
This patch fix this bug, and also skip useless memory copy to improve a bit of performance.

Types of changes

What types of changes does your code introduce to Doris?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [] Documentation Update (if none of the other choices apply)
  • [] Code refactor (Modify the code structure, format the code, etc...)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have create an issue on (Fix ASAN error: heap-buffer-overflow in MemIndex::load_segment #4459), and have described the bug/feature there in detail
  • Compiling and unit tests pass locally with my changes
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] If this change need a document change, I have updated the document
  • [] Any dependent changes have been merged

Further comments

none

Copy link
Contributor

@morningman morningman left a comment

Choose a reason for hiding this comment

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

LGTM

@morningman
Copy link
Contributor

I'm curious, why hasn't this part of the code been a problem before?
It looks like this code has been around for a long time.

@morningman morningman added approved Indicates a PR has been approved by one committer. kind/fix Categorizes issue or PR as related to a bug. labels Aug 28, 2020
@acelyc111
Copy link
Member Author

I'm curious, why hasn't this part of the code been a problem before?
It looks like this code has been around for a long time.

I'm not clear, this issue will only happened when the value is null, and nullable byte is correctly copied

@morningman morningman merged commit 65cacbf into apache:master Aug 30, 2020
acelyc111 added a commit to acelyc111/incubator-doris that referenced this pull request Jan 20, 2021
…apache#4458)

Segment index file content is not set as 0 when it is constructed in write procedure, 
so when load index from this file, and meet a null VARCHAR cell,
the null field of this cell is 0, but the length field which is not initialized maybe a large random number,
then memory copy may cause overflow.
This patch fix this bug, and also skip useless memory copy to improve a bit of performance.
@yangzhg yangzhg mentioned this pull request Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by one committer. kind/fix Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants