Subject: Bug with chunked files

From: AsmodeusB <[email-masked]>
Date: Fri, 28 Apr 2023 12:42:10 -0400

It looks like there is a bug with chunked files where the file size is an
integer multiple of the chunk size.

Version: 8.8.2 built with go1.19.3
(debian-backports 8.8.2-2~bpo11+1 linux amd64)

To replicate:
- Create a file that is exactly 1MB, for example (1048576 bytes)
  dd if=/dev/random bs=1M count=1 of=1m
- nncp-file to send it, -chunked 512  (or 256, 128, 64, 32, 16, 8, 4, 2, 1)
(I was using nncp-xfer to transfer)
- nncp-toss to get the .chunk and .meta files on the destination node in
incoming/
- nncp-reass the file to hit the error:

ERROR Reassembling chunked file "/var/spool/incoming/1m.nncp.meta": chunk
1: invalid size
(this was using 512k chunks; it's always the last chunk it complains about)

If the chunks are concatenated together, the original file is recovered, so
the issue appears to be with nncp-reass, not creation or transmission.

If the file is instead one byte smaller (1048575 bytes), it reassembles
without error; same with one byte larger.

The problem isn't related to a power of 2.  For example, a 6KB file (6144
bytes) -chunked 3, 2, or 1 will hit the same error.