studyzy/imewlconverter · error · InvalidDataException
有异常的词库,解析失败
Error message
有异常的词库,解析失败
What it means
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.
Source
Thrown at src/ImeWlConverter.Formats/BaiduBdict/BaiduBdictImporter.cs:58
while (input.Position < endPosition)
{
ct.ThrowIfCancellationRequested();
var entry = ReadOneWord(reader, input);
if (entry == null)
break;
if (entry.Word.Length > 0 && entry.Code != null)
results.Add(entry);
}
return results;
}
private static WordEntry? ReadOneWord(BinaryReader reader, Stream stream)
{
var len = reader.ReadInt32();
if (len > 1000)
throw new InvalidDataException("有异常的词库,解析失败");
if (len == 0)
return null;
var pinyinList = new string[len];
for (var i = 0; i < len; i++)
{
var smIndex = reader.ReadByte();
var ymIndex = reader.ReadByte();
if (smIndex < Shengmu.Length && ymIndex < Yunmu.Length)
pinyinList[i] = Shengmu[smIndex] + Yunmu[ymIndex];
else
pinyinList[i] = "";
}
var wordBytes = reader.ReadBytes(2 * len);
var word = Encoding.Unicode.GetString(wordBytes);
var hasValidPinyin = false;View on GitHub (pinned to 16744a12ed)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
// best-effort header sanity before full parse:
if (input.Length < 0x350) throw new InvalidDataException("too small to be a bdict"); Try / catch
try { var entries = importer.ParseBinary(stream, ct); }
catch (InvalidDataException ex) { ReportError($"unsupported/corrupt bdict: {ex.Message}"); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- 词条数量异常: {cnt},可能是文件格式不兼容
- 词库文件格式不正确,文件大小至少需要{UserWordBase}字节,当前为{fileSize}字节
- 未能成功解析任何词条,可能是文件格式不兼容或文件已损坏
AI-assisted analysis of studyzy/imewlconverter@16744a12ed (2026-08-13).
Data as JSON: /api/errors/7f4e118dd37d5bc4.
Report an issue: GitHub.