🧱 Chunk is a download manager for slow and unstable servers

Servers that ignore the Range header produce silently corrupted files #1

Open cuducos.me
Open opened by cuducos.me

Problem

downloadChunkWithContext accepts both 206 Partial Content and 200 OK responses to a ranged request (downloader.go:150). A server that ignores the Range header replies 200 OK with the entire file, which is then written at the chunk's offset via WriteAt (downloader.go:386). Every chunk therefore writes the whole file, chunks overlap and corrupt each other, and every chunk is marked as done in the progress file.

Impact

Silent data corruption with no error reported. The final file is much larger than the source and its bytes are wrong, yet the last status has err = nil. Because DownloadedFileBytes can exceed FileSizeBytes, IsFinished() also never returns true.

Reproduction (verified)

  • 64 KiB source file → 122,880-byte file on disk, 57,126/65,536 bytes wrong, download reported "success".
  • Same behavior through the CLI: 8 MiB source → 16.7 MiB output file.

Suggested fix

Reject 200 OK responses to ranged requests, or validate that the response body length matches the requested chunk size / Content-Range before writing.

Sign up or Sign in to add to the discussion.