lutzroeder/netron · error · Error

Expected ${this._position - this._length} more bytes. The fi

Error message

Expected ${this._position - this._length} more bytes. The file might be corrupted. Unexpected end of file.

What it means

Thrown by the binary reader's skip(offset) when skipping forward would move the read position past the end of the known stream length. It reports how many bytes beyond the file would be needed, which almost always means the input is truncated or not in the format the parser expects (so it computes a bogus offset).

Source

Thrown at source/browser.js:756

    get length() {
        return this._length;
    }

    stream(length) {
        const file = new browser.FileStream(this._chunks, this._size, this._start + this._position, length);
        this.skip(length);
        return file;
    }

    seek(position) {
        this._position = position >= 0 ? position : this._length + position;
    }

    skip(offset) {
        this._position += offset;
        if (this._position > this._length) {
            throw new Error(`Expected ${this._position - this._length} more bytes. The file might be corrupted. Unexpected end of file.`);
        }
    }

    peek(length) {
        length = length === undefined ? this._length - this._position : length;
        if (length < 0x10000000) {
            const position = this._fill(length);
            this._position -= length;
            return this._buffer.subarray(position, position + length);
        }
        const position = this._start + this._position;
        if (position % this._size === 0) {
            const index = Math.floor(position / this._size);
            const chunk = this._chunks[index];
            if (chunk && chunk.length === length) {
                return chunk;
            }
        }

View on GitHub (pinned to d8a543f5f8)

Solutions

  1. Re-download or re-export the model file and verify its size matches the source (truncation is the most common cause)
  2. Confirm you are using the correct loader/format for the file (e.g. don't open a protobuf text file with the binary reader)
  3. If the file is intentional and large, verify it isn't cut off at a chunk boundary (0x10000000-byte chunks) by checking declared vs actual length
  4. Validate the file with an upstream tool (e.g. protobuf decoder or the framework's own checker) before loading
Defensive patterns

Strategy: validation

Validate before calling

// Before parsing, sanity-check declared size vs actual blob size
const stat = await context.size(file);
if (declaredLength > stat) {
  throw new Error(`File truncated: declared ${declaredLength}, have ${stat}`);
}

Try / catch

try {
  reader.skip(offset);
} catch (e) {
  if (e.message.includes('Unexpected end of file')) {
    // treat as corrupt input: report and abort load, don't retry
    return { ok: false, reason: 'truncated-file' };
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling reader.skip(offset) with an offset larger than the remaining bytes (this._position + offset > this._length); typically reached while parsing a binary model whose header declares sizes exceeding the actual file, or when a text/JSON file is passed to a binary parser.

Common situations: Truncated downloads or partial uploads of .onnx/.pb/.bin files; parsing a file with the wrong format identifier so the wrong reader is selected; files >256MB chunk boundaries mis-declared; corrupt archives where offsets are garbage.

Related errors


AI-assisted analysis of lutzroeder/netron@d8a543f5f8 (2026-08-27). Data as JSON: /api/errors/1bc2849c16949b02. Report an issue: GitHub.