-
Notifications
You must be signed in to change notification settings - Fork 70
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
Get chunk size fix #382
Merged
Merged
Get chunk size fix #382
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b85b8e3
- Updated the logic for calculating the chunk size when the chunk ind…
traktion 5adf858
- Add test coverage for seeking indices on a medium sized file
traktion 31450a4
- Reverted the logic for calculating the chunk size when the chunk in…
traktion d47496d
- Clippy: Removed superfluous .write(true), as .append(true) is present.
traktion 7cdd5fc
- fmt fix
traktion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 the aim of the original code block is :
always have chunks[2] to be the one holding extra bytes, when file_size is small AND non-dividable by 3.
say, if file_size is 1024, then chunk[0] & chunk[1] to be 341, chunk[2] to be 342
with the change, all three chunks will then be 341, which will cause a data loss ?
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 can create a unit test with the above scenario and test it out. It's good to understand the context behind this.
From testing, it definitely wasn't working right and this seemed to fix it. However, it sounds like there could be the edge cases described.
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.
Considering the above and looking at the code again, I think the bug is actually in the
seek_info
routine. I see there are a bunch of others that useget_chunk_size
and they likely need the logic as you describe.Given seeking is always from the start of the chunk and only the last chunk is oversized, we can use
get_chunk_size(file_size, 0)
in all cases. EDIT: Actually, that doesn't quite work either (at the upper boundary).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 there is also an issue with
overlapped_chunks
due toget_chunk_index
, as when you have a large 3rd chunk, it callsget_chunk_size(filesize, 0)
(like I thought may work above). However, if you have an oversized 3rd chunk, it returns 0 (instead of 2).In turn, that means
seek_info
reverts to start_index == 0, which corrupts the relative_pos value.I'm adding more tests to check these boundaries.
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.
Hi, @traktion ,
really appreciate your investigations and more tests is always appreciated.
meanwhile, I had a quick scan on self_encryption code, and doess see issues at
https://github.com/maidsafe/self_encryption/blob/master/src/lib.rs#L492
and
https://github.com/maidsafe/self_encryption/blob/master/src/lib.rs#L640
L492 uses remainder when divided by chunk_size of starting chunk, which will be incorrect when:
a, the starting chunk is oversized chunk
b, the position falls into the edge of the oversized chunk
L640 bearing the similar issue that using chunk_size of the first chunk.
I will see if can get some fixes and tests to it on Monday when back.
And will be really appreciated and merge your tests in, if you come up more, or even with a solution to it.
Thank you very much.
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've reverted my prior change and applied a new fix for L492.
I took a deeper look at L640 and it appears to be ok. While the remainder is incorrect, the final calculation is still valid and returns the correct index. I confirmed this with tests too. The logic is definitely a bit brain twisting though.
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.
great work !
really appreciate it.