studyzy/imewlconverter · error · InvalidDataException

词库文件格式不正确,文件大小至少需要{UserWordBase}字节,当前为{fileSize}字节

Error message

词库文件格式不正确,文件大小至少需要{UserWordBase}字节,当前为{fileSize}字节

What it means

Win10MsPinyinSelfStudyImporter requires the DAT file to be at least 0x2400 (9216) bytes because the word-data region begins at that fixed offset. A smaller file cannot be a valid self-study dictionary, so the importer aborts immediately with InvalidDataException before reading any entries.

Source

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

using ImeWlConverter.Abstractions;
using ImeWlConverter.Abstractions.Enums;
using ImeWlConverter.Abstractions.Models;
using ImeWlConverter.Formats.Shared;

/// <summary>Win10 Microsoft Pinyin self-study dictionary importer (binary DAT format).</summary>
[FormatPlugin("win10mspyss", "Win10微软拼音(自学习词汇)", 130)]
public sealed partial class Win10MsPinyinSelfStudyImporter : BinaryFormatImporter
{
    private const int UserWordBase = 0x2400;
    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)

View on GitHub (pinned to 16744a12ed)

Solutions

  1. Verify the file is the Win10 self-study .dat and is at least 9216 bytes before importing.
  2. Re-export or re-copy the file completely from the IME data directory.
  3. Select the correct importer matching the actual file type (e.g. the standard win10mspy importer for the regular user dict).
Defensive patterns

Strategy: validation

Validate before calling

if (new FileInfo(path).Length < 0x2400)
    ReportError("not a valid win10mspyss file (too small)");

Try / catch

try { var entries = importer.ParseBinary(stream, ct); }
catch (InvalidDataException ex) { ReportError(ex.Message); }

Prevention

When it happens

Trigger: Feeding a small/non-DAT file (e.g. a few hundred bytes) as the win10mspyss format; a truncated copy of the self-study .dat; a file from a different Microsoft IME format that is coincidentally tiny.

Common situations: Wrong file/format chosen; a partial copy of the self-study .dat (normally under %AppData%); confusing this format with the regular Win10 Microsoft Pinyin user dictionary.

Related errors


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