lutzroeder/netron · error · Error

Expected more bytes. The file might be corrupted…

Error message

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

What it means

Thrown by the memory-backed stream's seek() when the requested position is beyond the end of the buffer or negative (negative positions are interpreted relative to the end, so only out-of-range values throw). It signals that a model parser attempted to jump past the data available, typically because internal offsets in the file are inconsistent with its actual size.

Solutions

  1. Verify the file size and integrity (re-download or re-export the model).
  2. Check the parser logic that computed the position — a stored offset/length field read with the wrong endianness or type can yield huge values.
  3. Wrap seek() calls in try-catch to convert this into a user-facing 'corrupted file' message.

Example fix

// before
stream.seek(offsetFromHeader);

// after
if (offsetFromHeader < 0 || offsetFromHeader > stream.length) {
    throw new Error(`Header offset ${offsetFromHeader} out of range for file of ${stream.length} bytes`);
}
stream.seek(offsetFromHeader);
Defensive patterns

Strategy: validation

Validate before calling

function safeSeek(stream, position) {
    const abs = position >= 0 ? position : stream.length + position;
    if (abs < 0 || abs > stream.length) {
        throw new Error(`seek(${position}) out of range for ${stream.length} bytes`);
    }
    stream.seek(position);
}

Try / catch

try { stream.seek(pos); } catch (e) { if (/more bytes/.test(e.message)) throw new Error('Model file appears truncated'); throw e; }

Prevention

When it happens

Trigger: Calling seek(position) with position > stream length or a negative position whose absolute value exceeds length; commonly triggered by model-format code following a stored offset field into a truncated file.

Common situations: Truncated or corrupted model files (interrupted download/export), files where a length-prefixed section claims more data than present, or passing a negative seek offset when the intent was relative skipping.

Related errors


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

Appendix: source

Thrown at source/node.js:33

    get position() {
        return this._position;
    }

    get length() {
        return this._length;
    }

    stream(length) {
        const stream = new node.FileStream(this._file, this._start + this._position, length, this._mtime);
        this.skip(length);
        return stream;
    }

    seek(position) {
        this._position = position >= 0 ? position : this._length + position;
        if (this._position > this._length || this._position < 0) {
            throw new Error(`Expected ${this._position - this._length} more bytes. The file might be corrupted. Unexpected end of file.`);
        }
    }

    skip(offset) {
        this._position += offset;
        if (this._position > this._length || this._position < 0) {
            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._position;

View on GitHub (pinned to d8a543f5f8)