studyzy/imewlconverter · error · InvalidDataException

词条数量异常: {cnt},可能是文件格式不兼容

Error message

词条数量异常: {cnt},可能是文件格式不兼容

What it means

After the size check passes, the importer reads a 4-byte word count at offset 12. A real self-study file has a sane positive count bounded well under 100000; a negative value or one exceeding 100000 means the bytes at offset 12 are not a real count — the file is corrupt or an incompatible format revision. Aborts with InvalidDataException.

Source

Thrown at src/ImeWlConverter.Formats/Win10MsSelfStudy/Win10MsPinyinSelfStudyImporter.cs:32

    private const int EntrySize = 60;

    protected override IReadOnlyList<WordEntry> ParseBinary(Stream input, CancellationToken ct)
    {
        var results = new List<WordEntry>();
        var fileSize = input.Length;

        if (fileSize < UserWordBase)
            throw new InvalidDataException(
                $"词库文件格式不正确,文件大小至少需要{UserWordBase}字节,当前为{fileSize}字节");

        // Read word count at offset 12
        input.Position = 12;
        var countBytes = new byte[4];
        input.ReadExactly(countBytes, 0, 4);
        var cnt = BitConverter.ToInt32(countBytes, 0);

        if (cnt < 0 || cnt > 100000)
            throw new InvalidDataException($"词条数量异常: {cnt},可能是文件格式不兼容");

        for (var i = 0; i < cnt; i++)
        {
            ct.ThrowIfCancellationRequested();

            var curIdx = UserWordBase + i * EntrySize;

            if (curIdx + EntrySize > fileSize)
                break;

            // Read word length at curIdx + 10
            input.Position = curIdx + 10;
            var wordLen = input.ReadByte() & 0xFF;

            if (wordLen <= 0 || wordLen > 24)
                continue;

            // Read word at curIdx + 12

View on GitHub (pinned to 16744a12ed)

Solutions

  1. Confirm the file is specifically the Win10 self-study .dat, not another Microsoft IME dictionary variant.
  2. If the file is the standard Win10 MS Pinyin user dictionary, use the regular win10mspy importer instead.
  3. Re-export the file from a supported IME build.
Defensive patterns

Strategy: try-catch

Try / catch

try { var entries = importer.ParseBinary(stream, ct); }
catch (InvalidDataException ex) { ReportError($"incompatible win10mspyss format: {ex.Message}"); }

Prevention

When it happens

Trigger: A file that passed the 9216-byte size check but is not actually the self-study format (so offset-12 bytes are garbage); a different Win10/Office IME dictionary variant with a different header layout; byte-level corruption in the header region.

Common situations: A differently-versioned Microsoft pinyin dictionary whose header differs; a file that is large enough by coincidence but is another format entirely (e.g. another MS IME dictionary).

Related errors


AI-assisted analysis of studyzy/imewlconverter@16744a12ed (2026-08-13). Data as JSON: /api/errors/91cca869280863ea. Report an issue: GitHub.