maidsafe / self_encryption

file self encryptor
Other
118 stars 70 forks source link

get_chunk_size() is returning incorrect file size when chunk index is > 1 and the file size is less than 3 * MAX_CHUNK_SIZE #381

Open traktion opened 4 months ago

traktion commented 4 months ago

Thank you for contributing to the project! We recommend you check out our "Contributing to the SAFE Network" guide if you haven't already.

Describe the bug

Originally found through integrating sn_client libraries into sn_httpd: https://github.com/maidsafe/safe_network/issues/1621#issue-2245520089

In short, when attempting to retrieve small parts of medium sized files (up to 1.5 MB), the relative_pos is incorrectly calculated for index 2+. This results in relative_pos being too low, causing an overlap with prior calls to seek_info when stepping through a file.

To Reproduce Steps to reproduce the behavior:

  1. Call seek_info with a file smaller than 1.5 MB, using a small length such as 64 KB and increment the pos by 64 KB each time.
  2. Once index 2 is referenced, the relative_pos will return duplicate bytes from the prior call.

Expected behavior There should be no duplicate bytes returned from prior calls to seek_info().

Screenshots This is a comparison between 2 files, one using a large length (512 KB) which is successful, vs one which used 128 KB and had duplicate bytes:

Screenshot from 2024-04-16 09-53-55

Desktop (please complete the followin g information):

Smartphone (please complete the following information):

Additional context

traktion commented 4 months ago

I have a PR to fix this issue, but I don't think I have permission to create a branch.

traktion commented 4 months ago

PR here: https://github.com/maidsafe/self_encryption/pull/382