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

fix: fix a potential out of bounds issue in fuse #6847

Merged
merged 1 commit into from
Jan 29, 2020
Merged

Conversation

Stebalien
Copy link
Member

@Stebalien Stebalien commented Jan 28, 2020

We likely encountered a file that misreported its size. That or there was no bug here and we hit an issue somewhere else. Regardless, there's no reason not to simplify this code and this should fix the issue.

Copy link
Contributor

@aschmahmann aschmahmann left a comment

Choose a reason for hiding this comment

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

This PR fails the linter bc the min function is no longer used. Also, I left a question on the change itself.

buf := resp.Data[:min(req.Size, int(int64(r.Size())-req.Offset))]
// Data has a capacity of Size
buf := resp.Data[:int(req.Size)]
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the out of bounds error that this is fixing? If the issue was that buf could be empty then we still get the error.

Have we introduced another possible out of bounds error here if the response data is less than the request size? Is it really safe to remove the min check here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The fuse library gives us a Data buffer a capacity of Size. I believe the issue was that Size()` reported an incorrect size (-1, 0, etc.).

Copy link
Contributor

@aschmahmann aschmahmann Jan 28, 2020

Choose a reason for hiding this comment

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

I could be wrong here, but I don't think the issue was calculating buf := resp.Data[-1] because that would throw an invalid slice index instead of the index out of range error that was reported in the issue. If so then the panic was caused by the index being too large not too small, and therefore this fix likely won't resolve the issue.

Also, is it possible that req.Size is bigger than the buffer and so we'll run into an out of bounds error with this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

But you're right, -1 would give us a different error. The only sane answer is that Size is too big.

We likely encountered a file that misreported its size. That or there was no bug
here and we hit an issue somewhere else. Regardless, there's no reason not to
simplify this code and this should fix the issue.
@Stebalien
Copy link
Member Author

I'm going to merge this as it's less broken (but there's still something wrong).

@Stebalien Stebalien merged commit 8e0f92b into master Jan 29, 2020
@Stebalien Stebalien deleted the fix/6765 branch January 29, 2020 02:30
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.

3 participants