Fix TFTP problems with large files.

TFTP fails with a timeout when the transfer exceeds 128K blocks.
The block field in an ACK packet is 16 bits, so large transfers
need to deal with this field wrapping. Testing failure meant
that it worked for the first wrap, but not for subsequent ones.

Having fixed the block number problem, file size calculations
accidentally being done in 32 bits not 64 bits then broke
transfers larger than 2G or maybe 4G.

The first problem was probably introduced in commit
ebef27f321 and has not appeared
in a stable release. The second appears to have been there forever.
Clearly, nobody is mad enough to transfer multi-gigabyte files
over TFTP.

Thanks to Jean-François JUBLIN for spotting this and supplying
useful packet dumps that made it easy to diagnose.
This commit is contained in:
Simon Kelley
2025-08-21 12:49:09 +01:00
parent 1677c6e10b
commit d81b1d76a0
3 changed files with 28 additions and 14 deletions

View File

@@ -1118,7 +1118,7 @@ struct tftp_file {
struct tftp_transfer {
int sockfd;
time_t retransmit, start;
unsigned int lastack, block, blocksize, windowsize, timeout, expansion;
unsigned int lastack, block, ackblock, blocksize, windowsize, timeout, expansion;
off_t offset;
union mysockaddr peer;
union all_addr source;