Skip to content

Trailing zeroes in patched file #20

@Lupus

Description

@Lupus

I'm trying to use go-sync as a library and run into random corruption of patched files. Looking at hex diff, pattern is always the same - patched file size gets rounded up to block size and extra space is filled with zeroes:

--- /dev/fd/63  2021-12-23 15:03:49.189605458 +0000
+++ /dev/fd/62  2021-12-23 15:03:49.189605458 +0000
@@ -189527,4 +189527,4 @@
 002e6bd0  bc 35 c4 35 c8 35 cc 35  d0 35 00 00 00 00 00 00  |.5.5.5.5.5......|
 002e6be0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 *
-00303600
+00304000

Block size that I use is 4096 (0x1000), original file size is 3159552, after patching it ends up as 3162112 - 771.375 blocks vs 772.0 blocks.

I double checked that I pass the correct FileSize and BlockSize. Checksum data is read separately and is 15440 bytes long, which looks sane 5440/(4+16) = 772. BlockCount in summary is set to length of checksums array, returned by chunks.LoadChecksumsFromReader. Then I construct blob source like this:

resolver := blocksources.MakeFileSizedBlockResolver(uint64(summary.GetBlockSize()), summary.GetFileSize())
blockSource := blocksources.NewReadSeekerBlockSource(myReadSeeker, resolver)

Is there something that I'm missing? Glancing at the code MakeFileSizedBlockResolver should do the right thing, and truncate last partial block end offset to be no larger than the file, but somehow those trailing zeroes crip in.

go-sync v0.0.0-20200808161209-d9b3aeb508db

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions