{"record":{"id":"7f4e118dd37d5bc4","repo":"studyzy/imewlconverter","slug":"error-7f4e11","errorCode":null,"errorMessage":"有异常的词库，解析失败","messagePattern":"有异常的词库，解析失败","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"src/ImeWlConverter.Formats/BaiduBdict/BaiduBdictImporter.cs","lineNumber":58,"sourceCode":"        while (input.Position < endPosition)\n        {\n            ct.ThrowIfCancellationRequested();\n\n            var entry = ReadOneWord(reader, input);\n            if (entry == null)\n                break;\n            if (entry.Word.Length > 0 && entry.Code != null)\n                results.Add(entry);\n        }\n\n        return results;\n    }\n\n    private static WordEntry? ReadOneWord(BinaryReader reader, Stream stream)\n    {\n        var len = reader.ReadInt32();\n        if (len > 1000)\n            throw new InvalidDataException(\"有异常的词库，解析失败\");\n        if (len == 0)\n            return null;\n\n        var pinyinList = new string[len];\n        for (var i = 0; i < len; i++)\n        {\n            var smIndex = reader.ReadByte();\n            var ymIndex = reader.ReadByte();\n            if (smIndex < Shengmu.Length && ymIndex < Yunmu.Length)\n                pinyinList[i] = Shengmu[smIndex] + Yunmu[ymIndex];\n            else\n                pinyinList[i] = \"\";\n        }\n\n        var wordBytes = reader.ReadBytes(2 * len);\n        var word = Encoding.Unicode.GetString(wordBytes);\n\n        var hasValidPinyin = false;","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/studyzy/imewlconverter/blob/16744a12ed5064896cf39095163e44b367aaada1/src/ImeWlConverter.Formats/BaiduBdict/BaiduBdictImporter.cs#L40-L76","documentation":"BaiduBdictImporter.ReadOneWord reads a 4-byte little-endian length (number of pinyin/character units in one entry). A genuine bdict entry is short; if len exceeds 1000 the parser assumes the stream is misaligned or the file is corrupt/not-a-real-bdict and aborts with InvalidDataException.","triggerScenarios":"Feeding a non-bdict file (e.g. an SCEL, QQPY, or plain text) to the bdict importer; a truncated/corrupted bdict where the read position drifted; an unsupported bdict revision whose different binary layout causes the length field to read as garbage.","commonSituations":"Wrong format selected for the input file; a partially downloaded or byte-corrupted bdict; a bdict exported by a newer Baidu IME version with a changed header/offset structure (the importer assumes header end-position at 0x60 and words at 0x350).","solutions":["Confirm the file is genuinely a Baidu bdict and re-select the correct importer for its real source app.","Re-download or re-export the bdict to rule out truncation/corruption.","If it is a new bdict revision, the importer's fixed offsets (0x60 end-position, 0x350 word start) likely need updating to match the new layout."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// best-effort header sanity before full parse:\nif (input.Length < 0x350) throw new InvalidDataException(\"too small to be a bdict\");","typeGuard":null,"tryCatchPattern":"try { var entries = importer.ParseBinary(stream, ct); }\ncatch (InvalidDataException ex) { ReportError($\"unsupported/corrupt bdict: {ex.Message}\"); }","preventionTips":["Pick the importer whose source app matches the file (Baidu bdict, not SCEL/QQPY).","Keep a known-good bdict sample to validate importer behavior against.","Re-download/re-export when corruption is suspected before debugging offsets."],"tags":["baidu","bdict","binary","corrupt","import"],"backgroundTag":null,"analyzedSha":"16744a12ed5064896cf39095163e44b367aaada1","analyzedAt":"2026-08-13T19:53:09.031Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}