{"record":{"id":"2d47c7eacb04a30a","repo":"subhra74/xdm","slug":"eof-file-corrupted-singlesourcehttpdownloader","errorCode":null,"errorMessage":"EOF :: File corrupted","messagePattern":"EOF :: File corrupted","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"app/XDM/XDM.Core/Downloader/Progressive/SingleHttp/SingleSourceHTTPDownloader.cs","lineNumber":390,"sourceCode":"                                    }\r\n                                    catch (IOException ioe)\r\n                                    {\r\n                                        Log.Debug(ioe, \"AssemblePieces\");\r\n                                        throw new AssembleFailedException(ErrorCode.DiskError, ioe);\r\n                                    }\r\n                                    totalBytes += x;\r\n                                }\r\n                            }\r\n                            else\r\n                            {\r\n                                while (len > 0)\r\n                                {\r\n                                    if (this.cancelFlag.IsCancellationRequested) return;\r\n                                    var x = infs.Read(buf, 0, (int)Math.Min(buf.Length, len));\r\n                                    if (x == 0)\r\n                                    {\r\n                                        Log.Debug(\"EOF :: File corrupted\");\r\n                                        throw new Exception(\"EOF :: File corrupted\");\r\n                                    }\r\n                                    try\r\n                                    {\r\n                                        outfs.Write(buf, 0, x);\r\n                                    }\r\n                                    catch (IOException ioe)\r\n                                    {\r\n                                        Log.Debug(ioe, \"AssemblePieces\");\r\n                                        throw new AssembleFailedException(ErrorCode.DiskError, ioe);\r\n                                    }\r\n                                    len -= x;\r\n                                    totalBytes += x;\r\n                                    var prg = (int)(totalBytes * 100 / FileSize);\r\n                                    if (state!.ConvertToMp3) prg /= 2;\r\n                                    this.OnAssembleProgressChanged(prg);\r\n                                }\r\n                            }\r\n                        }\r","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/subhra74/xdm/blob/1ca5a25aae007826c859c81bea494e7c102e1242/app/XDM/XDM.Core/Downloader/Progressive/SingleHttp/SingleSourceHTTPDownloader.cs#L372-L408","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Delete the partial/temp piece files and re-download from scratch - assembly cannot complete with corrupt pieces.","Re-run the download with fresh pieces; verify each piece's size matches its expected length before assembling.","Check the disk for corruption if piece files are repeatedly short.","Upgrade/patch the downloader so pieces that fail validation are re-fetched instead of persisted."],"exampleFix":"// before\nAssemblePieces(pieces); // one piece truncated -> Exception \"EOF :: File corrupted\"\n// after\nforeach (var p in pieces)\n    if (new FileInfo(p.Path).Length != p.ExpectedLength)\n        ReDownloadPiece(p); // validate before assembling\nAssemblePieces(pieces);","handlingStrategy":"validation","validationCode":"// before assembling, validate pieces\nforeach (var p in pieces)\n    if (new FileInfo(p.FilePath).Length != p.ExpectedLength)\n        throw new InvalidDataException($\"Piece {p.Id} truncated\");","typeGuard":null,"tryCatchPattern":"try { AssemblePieces(); }\ncatch (Exception e) when (e.Message == \"EOF :: File corrupted\") {\n    DeletePieceFiles();\n    RedownloadAll();\n}","preventionTips":["Validate piece sizes against expected lengths before merge","Re-fetch truncated pieces instead of persisting them","Guard temp files against process kill mid-write","Check disk health if corruption recurs"],"tags":["assembly","corrupt-file","eof"],"backgroundTag":"checksum-mismatch","analyzedSha":"1ca5a25aae007826c859c81bea494e7c102e1242","analyzedAt":"2026-09-13T20:37:40.968Z","contentChangedAt":"2026-09-13T20:37:40.968Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}