🧱 Chunk is a download manager for slow and unstable servers

Truncated chunk responses silently corrupt the file and are permanent after resume #2

Open cuducos.me
Open opened by cuducos.me

Problem

prepareAndStartDownload writes whatever bytes arrived and marks the chunk done without verifying that the body length matches the requested chunk size or the Content-Range header (downloader.go:385-397). A server that sends a short body leaves a zero-filled hole in the file; the chunk is then recorded as done (p.done(idx, written)), so on resume it is skipped forever.

Impact

Silent corruption with no error reported — exactly the failure mode of an unstable server. The hole is never re-fetched, even on later attempts.

Reproduction (verified)

Server always returning 4096 bytes per request → 61,204/65,536 bytes wrong, err = nil, download reported "success".

Suggested fix

Check that len(body) == chunk.size() (or validate Content-Range) before writing and marking the chunk done; treat a mismatch as a failed chunk.

Sign up or Sign in to add to the discussion.