lutzroeder/netron · error · RangeError
Unexpected end of file.
Error message
Unexpected end of file.
What it means
A RangeError raised by the generic text/protobuf reader's _unexpected() handler, which is wired as the out-of-bounds callback for array/string access helpers (floats, doubles, skip, skipVarint). It fires when one of those helpers would read past the end of the input while decoding a message.
Source
Thrown at source/protobuf.js:471
}
}
return true;
}
entry(obj, key, value) {
this.skipVarint();
this.skip(1);
let k = key();
if (!Number.isInteger(k) && typeof k !== 'string') {
k = Number(k);
}
this.skip(1);
const v = value();
obj[k] = v;
}
_unexpected() {
throw new RangeError('Unexpected end of file.');
}
};
protobuf.BufferReader = class extends protobuf.BinaryReader {
constructor(buffer, offset = 0) {
super();
this._buffer = buffer;
this._length = buffer.length;
this._position = offset;
this._view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
}
skipVarint() {
do {
if (this._position >= this._length) {
this._unexpected();
}View on GitHub (pinned to d8a543f5f8)
Solutions
- Verify the input buffer is complete and you are decoding starting at the correct offset.
- Confirm the message type matches the schema the data was encoded with.
- Catch RangeError around decode and surface a 'corrupted input' error to callers.
Defensive patterns
Strategy: try-catch
Validate before calling
if (buffer.length === 0) {
throw new Error('Refusing to decode empty buffer');
} Try / catch
try { const msg = Proto.decode(buf); } catch (e) { if (e instanceof RangeError && e.message === 'Unexpected end of file.') throw new Error('Corrupted or truncated protobuf input'); throw e; } Prevention
- Validate buffer completeness (length/checksum) before decode.
- Ensure slice offsets are within bounds when splitting payloads.
- Decode with the exact schema the producer used.
When it happens
Trigger: Decoding a message whose declared repeated-field count or varint length implies more bytes than remain; _unexpected is invoked by the helper library when the underlying index is out of bounds.
Common situations: Truncated serialized protos, wrong-length buffers sliced with bad offsets, or decoding a payload with the wrong message type so lengths are misinterpreted.
Related errors
AI-assisted analysis of lutzroeder/netron@d8a543f5f8 (2026-08-27).
Data as JSON: /api/errors/531ace66f59ff227.
Report an issue: GitHub.