{"record":{"id":"b7242bbcdd139014","repo":"ruvnet/ruflo","slug":"string-length-len-exceeds-remaining-buffer","errorCode":null,"errorMessage":"String length ${len} exceeds remaining buffer","messagePattern":"String length (.+?) exceeds remaining buffer","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/appliance/gguf-engine.ts","lineNumber":99,"sourceCode":"  readU8(): number  { const v = this.buf.readUInt8(this.offset); this.offset += 1; return v; }\n  readI8(): number  { const v = this.buf.readInt8(this.offset); this.offset += 1; return v; }\n  readU16(): number { const v = this.buf.readUInt16LE(this.offset); this.offset += 2; return v; }\n  readI16(): number { const v = this.buf.readInt16LE(this.offset); this.offset += 2; return v; }\n  readU32(): number { const v = this.buf.readUInt32LE(this.offset); this.offset += 4; return v; }\n  readI32(): number { const v = this.buf.readInt32LE(this.offset); this.offset += 4; return v; }\n  readF32(): number { const v = this.buf.readFloatLE(this.offset); this.offset += 4; return v; }\n  readF64(): number { const v = this.buf.readDoubleLE(this.offset); this.offset += 8; return v; }\n  readU64(): bigint { const v = this.buf.readBigUInt64LE(this.offset); this.offset += 8; return v; }\n  readI64(): bigint { const v = this.buf.readBigInt64LE(this.offset); this.offset += 8; return v; }\n  /** Safe for values up to 2^53. Real GGUF files never exceed this for tensor/kv counts. */\n  readU64AsNumber(): number { return Number(this.readU64()); }\n  readBool(): boolean { return this.readU8() !== 0; }\n\n  /** GGUF string: [length u64 LE][utf-8 bytes]. */\n  readString(): string {\n    const len = this.readU64AsNumber();\n    if (len === 0) return '';\n    if (len > this.remaining) throw new Error(`String length ${len} exceeds remaining buffer`);\n    const s = this.buf.toString('utf-8', this.offset, this.offset + len);\n    this.offset += len;\n    return s;\n  }\n}\n\n// ── GGUF Value Reading ──────────────────────────────────────\n\n/** Read a typed scalar from the buffer (shared by value and array-element readers). */\nfunction readScalar(reader: BufferReader, t: number): unknown {\n  switch (t) {\n    case GgufValueType.UINT8:   return reader.readU8();\n    case GgufValueType.INT8:    return reader.readI8();\n    case GgufValueType.UINT16:  return reader.readU16();\n    case GgufValueType.INT16:   return reader.readI16();\n    case GgufValueType.UINT32:  return reader.readU32();\n    case GgufValueType.INT32:   return reader.readI32();\n    case GgufValueType.FLOAT32: return reader.readF32();","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/cli/src/appliance/gguf-engine.ts#L81-L117","documentation":"BufferReader.readString decodes a GGUF string as [u64 length][utf-8 bytes]; if the declared length exceeds the bytes remaining in the buffer, it throws rather than reading past the end. parseGgufHeader only reads the first 256 KB of the file, so this fires on truncated/corrupt files, headers whose metadata exceeds that window, or a reader desynchronized by an earlier malformed field.","triggerScenarios":"parseGgufHeader on a partially downloaded .gguf; a model whose metadata block is larger than the 256 KB read window; buffer misalignment after an unknown value type consumed the wrong byte count; a non-GGUF binary that happened to pass the magic check.","commonSituations":"Interrupted downloads of multi-GB models; git-lfs pointer files fetched as raw bytes; files from converters emitting non-standard metadata ordering.","solutions":["Verify the file size and re-download/restore the model (compare checksums if the source publishes them)","Check the magic and version first so corrupt files fail fast with a clearer error","If large metadata is expected, read a bigger prefix than 256 KB before parsing","Keep the reader aligned: treat unknown value types as fatal instead of skipping bytes"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const { size } = await stat(modelPath);\nif (size < 4096) throw new Error(`model file suspiciously small: ${size} bytes`);\n// magic/version pre-check also keeps the reader aligned\nconst meta = await parseGgufHeader(modelPath);","typeGuard":null,"tryCatchPattern":"try { meta = await parseGgufHeader(path); }\ncatch (e) { if (e instanceof Error && /String length|GGUF/.test(e.message)) { rejectModel(path, e.message); } else throw e; }","preventionTips":["Verify downloads with checksums before parsing","Reject unknown value types fatally so the reader never desyncs mid-metadata","Keep a size floor sanity check before parsing model files"],"tags":["gguf","binary-parsing","file-format","truncated-file","nodejs"],"backgroundTag":"malformed-binary-file","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}