Skip to content

Fix for last block is not multiple of blocksize #84

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dh-apporto
Copy link

@dh-apporto dh-apporto commented Aug 7, 2025

Fix: .zsync truncates if source file is not a multiple of block size

This PR fixes an issue where zsyncmake2 would truncate the .zsync "Length" and omit the last partial block if the source file was not an exact multiple of the block size.

  • Ensures the final block and length in the .zsync are always correct, even for files not block-aligned.
  • Tested with files of various sizes and block sizes.

Caveats

I have not worked with C++ for many years. This code fix was generated by AI in github copilot claude sonnet 4 when I described the problem I was encountering. One thing to note, even though the file is now being copied across completely (verified with md5sum on source and destination file), the used count is not accurate in the output:

$ strings test-release.tgz.zsync  | head
Blocksize: 65536
Filename: test-release.tgz
Hash-Lengths: 2,3,5
Length: 3934466485
MTime: Wed, 06 Aug 2025 23:01:43 +0000
SHA-1: b0165cf9f0d86870327375e00495b87711476896
URL: test-release.tgz
zsync: 2.0.0-alpha-1

# /tmp/zsync2-63-1608115-x86_64.AppImage -o appliance-release.tgz http://10.200.100.59/test-release.tgz.zsync 
zsync2 version 2.0.0-alpha-1 (commit 1608115), build 63 built on 2023-03-04 00:30:21 UTC 
Checking for changes...
Using CA bundle found on system: /etc/ssl/certs/ca-certificates.crt
Using CA bundle found on system: /etc/ssl/certs/ca-certificates.crt
/opt/downloads/appliance-release.tgz found, using as seed file
Target file: /opt/downloads/appliance-release.tgz
Reading seed file: /opt/downloads/appliance-release.tgz
Usable data from seed files: 100.000000%
Renaming temp file
Fetching remaining blocks
Verifying downloaded file
checksum matches OK
used 3934519296 local, fetched 0
           ^^^^^^^^^^-------- here
           
           
# ls -l appliance-release.tgz 
-rw------- 1 root root 3934466485 Aug  7 21:48 appliance-release.tgz

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.

1 participant