{"record":{"id":"245851c3cdef599c","repo":"lutzroeder/netron","slug":"expected-position-length-this-length-more","errorCode":null,"errorMessage":"Expected ${position + length - this._length} more bytes. The file might be corrupted. Unexpected end of file.","messagePattern":"Expected (.+?) more bytes\\. The file might be corrupted\\. Unexpected end of file\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"source/hdf5.js","lineNumber":667,"sourceCode":"    float64() {\n        const position = this.take(8);\n        return this._view.getFloat64(position, true);\n    }\n\n    size(terminator) {\n        const position = this._position;\n        let size = 0;\n        while (this.byte() !== terminator) {\n            size++;\n        }\n        this._position = position;\n        return size;\n    }\n\n    take(length) {\n        const position = this.position;\n        if (position + length > this._length) {\n            throw new Error(`Expected ${position + length - this._length} more bytes. The file might be corrupted. Unexpected end of file.`);\n        }\n        if (!this._view || position < this._window || position + length > this._window + this._view.byteLength) {\n            this._window = position;\n            const current = this._stream.position;\n            this._stream.seek(this._window);\n            const buffer = this._stream.read(Math.min(0x100, this._length - this._window)).slice();\n            this._view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n            this._stream.seek(current);\n        }\n        this._position += length;\n        return position - this._window;\n    }\n};\n\nhdf5.SymbolTableNode = class {\n\n    constructor(reader, offset) {\n        const position = reader.position;","sourceCodeStart":649,"sourceCodeEnd":685,"githubUrl":"https://github.com/lutzroeder/netron/blob/d8a543f5f847ef596aa58858d6adcf5d75545f7f/source/hdf5.js#L649-L685","documentation":"take(length) is the primitive that reserves length bytes at the current position; it throws when position + length runs past the end of the file image. Higher-level readers (variable-length integers, strings, object headers) all funnel through take(), so this error usually surfaces while decoding a header whose declared size does not fit in the remaining bytes.","triggerScenarios":"Any read that requests more bytes than remain: parsing an object header continuation, a symbol table message, a data layout message, or an attribute whose stated length extends past EOF. It also fires when a length field decoded from earlier garbage (e.g. wrong-endian or version-mismatched parse) produces an oversized take(n).","commonSituations":"Truncated HDF5 files (interrupted writes are common with HDF5), files that exceed the reader's supported HDF5 version (later versions add header fields that shift offsets and inflate subsequent length reads), or plain non-HDF5 binary data fed to the parser.","solutions":["Verify the file opens in the official HDF5 tools; if not, restore/re-export the file.","Ensure you are passing the raw, untruncated ArrayBuffer/File (no slicing, no compression) to the reader.","Check the file's HDF5 library version (superblock version field) against what this library supports and re-export with an older format if needed.","If the file is valid and supported, file an issue with a minimal reproducing file."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"function canTake(reader, length) {\n  const pos = reader.position;\n  return length >= 0 && pos + length <= reader._length;\n}\nif (canTake(reader, headerSize)) reader.take(headerSize); else throw new Error('Truncated HDF5 header');","typeGuard":"function fitsInFile(position, length, fileLength) {\n  return position >= 0 && length >= 0 && position + length <= fileLength;\n}","tryCatchPattern":"try {\n  const bytes = reader.take(n);\n} catch (e) {\n  if (/Unexpected end of file/.test(e.message)) {\n    // abort parse, flag file as corrupt\n  } else throw e;\n}","preventionTips":["Validate declared header/attribute sizes against remaining file bytes when generating files.","Close HDF5 writers properly so headers are fully flushed.","Feed the reader the complete, uncompressed file image."],"tags":["hdf5","out-of-bounds-read","corrupt-file","binary-parsing","truncated-file"],"backgroundTag":"corrupt-file-unexpected-eof","analyzedSha":"d8a543f5f847ef596aa58858d6adcf5d75545f7f","analyzedAt":"2026-08-27T19:21:42.082Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}