{"record":{"id":"d4fdc329f5e399c6","repo":"QL-Win/QuickLook","slug":"the-minidump-stream-directory-is-outside-the-file","errorCode":null,"errorMessage":"The minidump stream directory is outside the file.","messagePattern":"The minidump stream directory is outside the file\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"QuickLook.Plugin/QuickLook.Plugin.DumpViewer/MinidumpReader.cs","lineNumber":117,"sourceCode":"        reader.BaseStream.Position = 0;\n\n        var header = new MinidumpHeader\n        {\n            Signature = reader.ReadUInt32(),\n            Version = reader.ReadUInt32(),\n            NumberOfStreams = reader.ReadUInt32(),\n            StreamDirectoryRva = reader.ReadUInt32(),\n            CheckSum = reader.ReadUInt32(),\n            TimeDateStamp = reader.ReadUInt32(),\n            Flags = reader.ReadUInt64(),\n        };\n\n        if (header.Signature != MinidumpSignature)\n            throw new InvalidDataException(\"The file does not have a minidump signature.\");\n\n        var directoryBytes = (long)header.NumberOfStreams * DirectoryEntrySize;\n        if (!CanRead(fileLength, header.StreamDirectoryRva, directoryBytes))\n            throw new InvalidDataException(\"The minidump stream directory is outside the file.\");\n\n        return header;\n    }\n\n    private static IEnumerable<MinidumpDirectory> ReadDirectories(BinaryReader reader, long fileLength, MinidumpHeader header)\n    {\n        reader.BaseStream.Position = header.StreamDirectoryRva;\n\n        for (var i = 0; i < header.NumberOfStreams; i++)\n        {\n            var directory = new MinidumpDirectory\n            {\n                Type = (MinidumpStreamType)reader.ReadUInt32(),\n                DataSize = reader.ReadUInt32(),\n                Rva = reader.ReadUInt32(),\n            };\n\n            if (directory.DataSize == 0 || CanRead(fileLength, directory.Rva, directory.DataSize))","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/QL-Win/QuickLook/blob/cb5d9c429c81d9796fac469da2a68efb5626946d/QuickLook.Plugin/QuickLook.Plugin.DumpViewer/MinidumpReader.cs#L99-L135","documentation":"Thrown when the stream directory described by the header does not fit inside the file. After validating the MDMP signature, the reader computes directoryBytes = NumberOfStreams * 12 and checks CanRead(fileLength, StreamDirectoryRva, directoryBytes); a false result means the directory region starts beyond EOF or overruns it. This indicates a truncated or structurally corrupt minidump.","triggerScenarios":"header.NumberOfStreams or header.StreamDirectoryRva hold bogus/huge values (e.g. from a partially written dump), or the file was cut short so the directory region (RVA + NumberOfStreams*12) extends past fileLength.","commonSituations":"A crash dump captured while the process was still being written and then the dumper died; disk-full during dump write; a minidump copied incompletely; bit-rot in NumberOfStreams producing an absurd count.","solutions":["Re-capture the dump ensuring the writer completes (check the file stops growing / writer process exits cleanly).","Validate integrity with a debugger (WinDbg/cdb -z) — if it also rejects the file, the dump is irrecoverable.","Add a pre-check: ensure StreamDirectoryRva + (long)NumberOfStreams * 12 <= fileLength before trusting the header.","Catch InvalidDataException and surface 'corrupt or incomplete minidump' to the user."],"exampleFix":"// before\nvar directoryBytes = (long)header.NumberOfStreams * DirectoryEntrySize;\nif (!CanRead(fileLength, header.StreamDirectoryRva, directoryBytes))\n    throw new InvalidDataException(\"...\");\n\n// after — caller-side guard before parsing\nlong need = (long)header.NumberOfStreams * 12 + header.StreamDirectoryRva;\nif (need > new FileInfo(path).Length) { /* not a complete dump */ }","handlingStrategy":"validation","validationCode":"// before parsing, ensure the header's directory region fits the file\nlong len = new FileInfo(path).Length;\n// (after reading header) check: header.StreamDirectoryRva + (long)header.NumberOfStreams*12 <= len","typeGuard":null,"tryCatchPattern":"try { var info = MinidumpReader.Read(path); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"outside the file\")) { /* corrupt/truncated dump */ }","preventionTips":["Ensure dump capture completes (writer exits cleanly, disk not full).","Verify dump integrity in WinDbg/cdb before relying on it.","Validate header region bounds against file length before trusting offsets."],"tags":["minidump","corruption","truncation","binary-parsing"],"backgroundTag":null,"analyzedSha":"cb5d9c429c81d9796fac469da2a68efb5626946d","analyzedAt":"2026-08-13T11:51:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}