subhra74/xdm · error · Exception

EOF :: File corrupted

Error message

EOF :: File corrupted

What it means

During SingleSourceHTTPDownloader.AssemblePieces, downloaded piece files are concatenated into the final output. If reading a piece stream returns 0 bytes while bytes are still expected (len > 0), the piece file is short/corrupted and a generic Exception "EOF :: File corrupted" is thrown.

Solutions

  1. Delete the partial/temp piece files and re-download from scratch - assembly cannot complete with corrupt pieces.
  2. Re-run the download with fresh pieces; verify each piece's size matches its expected length before assembling.
  3. Check the disk for corruption if piece files are repeatedly short.
  4. Upgrade/patch the downloader so pieces that fail validation are re-fetched instead of persisted.

Example fix

// before
AssemblePieces(pieces); // one piece truncated -> Exception "EOF :: File corrupted"
// after
foreach (var p in pieces)
    if (new FileInfo(p.Path).Length != p.ExpectedLength)
        ReDownloadPiece(p); // validate before assembling
AssemblePieces(pieces);
Defensive patterns

Strategy: validation

Validate before calling

// before assembling, validate pieces
foreach (var p in pieces)
    if (new FileInfo(p.FilePath).Length != p.ExpectedLength)
        throw new InvalidDataException($"Piece {p.Id} truncated");

Try / catch

try { AssemblePieces(); }
catch (Exception e) when (e.Message == "EOF :: File corrupted") {
    DeletePieceFiles();
    RedownloadAll();
}

Prevention

When it happens

Trigger: infs.Read(buf, 0, min(buf.Length, len)) returns 0 before the accumulated piece length is fully read - i.e. a piece file on disk is smaller than its recorded length, usually because a transfer was truncated earlier.

Common situations: Previous download session ended with an unexpected EOF (see error 14) leaving truncated piece files, disk corruption of temp piece files, interrupted process killing writes mid-piece.

Understand the failure class

Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.

Related errors


AI-assisted analysis of subhra74/xdm@1ca5a25aae (2026-09-13). Data as JSON: /api/errors/2d47c7eacb04a30a. Report an issue: GitHub.

Appendix: source

Thrown at app/XDM/XDM.Core/Downloader/Progressive/SingleHttp/SingleSourceHTTPDownloader.cs:390

                                    }
                                    catch (IOException ioe)
                                    {
                                        Log.Debug(ioe, "AssemblePieces");
                                        throw new AssembleFailedException(ErrorCode.DiskError, ioe);
                                    }
                                    totalBytes += x;
                                }
                            }
                            else
                            {
                                while (len > 0)
                                {
                                    if (this.cancelFlag.IsCancellationRequested) return;
                                    var x = infs.Read(buf, 0, (int)Math.Min(buf.Length, len));
                                    if (x == 0)
                                    {
                                        Log.Debug("EOF :: File corrupted");
                                        throw new Exception("EOF :: File corrupted");
                                    }
                                    try
                                    {
                                        outfs.Write(buf, 0, x);
                                    }
                                    catch (IOException ioe)
                                    {
                                        Log.Debug(ioe, "AssemblePieces");
                                        throw new AssembleFailedException(ErrorCode.DiskError, ioe);
                                    }
                                    len -= x;
                                    totalBytes += x;
                                    var prg = (int)(totalBytes * 100 / FileSize);
                                    if (state!.ConvertToMp3) prg /= 2;
                                    this.OnAssembleProgressChanged(prg);
                                }
                            }
                        }

View on GitHub (pinned to 1ca5a25aae)