{"record":{"id":"0a7e251cdbd96241","repo":"ruvnet/ruflo","slug":"buffer-too-small-to-contain-rvfa-preamble","errorCode":null,"errorMessage":"Buffer too small to contain RVFA preamble","messagePattern":"Buffer too small to contain RVFA preamble","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/appliance/rvfa-format.ts","lineNumber":312,"sourceCode":"  }\n}\n\n// ---------------------------------------------------------------------------\n// RvfaReader\n// ---------------------------------------------------------------------------\nexport class RvfaReader {\n  private buf: Buffer;\n  private header: RvfaHeader;\n\n  private constructor(buf: Buffer, header: RvfaHeader) {\n    this.buf = buf;\n    this.header = header;\n  }\n\n  /** Parse an RVFA image from an in-memory Buffer. */\n  static fromBuffer(buf: Buffer): RvfaReader {\n    if (buf.length < PREAMBLE_SIZE) {\n      throw new Error('Buffer too small to contain RVFA preamble');\n    }\n\n    // Magic\n    const magic = buf.subarray(0, MAGIC_SIZE).toString('ascii');\n    if (magic !== 'RVFA') {\n      throw new Error(`Invalid RVFA magic: expected \"RVFA\", got \"${magic}\"`);\n    }\n\n    // Version\n    const version = buf.readUInt32LE(MAGIC_SIZE);\n    if (version !== RVFA_VERSION) {\n      throw new Error(\n        `Unsupported RVFA version: ${version} (expected ${RVFA_VERSION})`,\n      );\n    }\n\n    // Header length\n    const headerLen = buf.readUInt32LE(MAGIC_SIZE + VERSION_SIZE);","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/cli/src/appliance/rvfa-format.ts#L294-L330","documentation":"RvfaReader.fromBuffer requires at least the 12-byte preamble (4 magic + 4 version + 4 header-length) before reading any field. This fires when the buffer is shorter than 12 bytes — an empty or near-empty image: a failed download saved as 0 bytes, an empty file, or a wrong path. No format field has even been read yet.","triggerScenarios":"`RvfaReader.fromBuffer(buf)` with an empty Buffer from readFile of an empty file (or a caught ENOENT defaulted to empty); a few-byte stub from an interrupted appliance fetch.","commonSituations":"An HTTP error body of length 0 written to disk as the .rvf image; sync tools that create the file before content arrives; tests passing placeholder buffers.","solutions":["Check buf.length >= 12 before calling fromBuffer","Verify the download: expected byte size and non-empty response body, not just HTTP 200","Re-download the .rvf appliance image from its gateway CID"],"exampleFix":"// before\nconst reader = RvfaReader.fromBuffer(await readFile(imgPath)); // 0-byte file → throws\n\n// after\nconst buf = await readFile(imgPath);\nif (buf.length < 12) throw new Error(`${imgPath} is ${buf.length}B — download failed, refetch`);\nconst reader = RvfaReader.fromBuffer(buf);","handlingStrategy":"validation","validationCode":"const buf = await readFile(imagePath);\nif (buf.length < 12) {\n  throw new Error('Appliance image empty or truncated — re-download from its CID');\n}\nconst reader = RvfaReader.fromBuffer(buf);","typeGuard":"function isRvfaCandidate(buf: Buffer): boolean {\n  return buf.length >= 12 && buf.subarray(0, 4).toString('ascii') === 'RVFA';\n}","tryCatchPattern":null,"preventionTips":["Verify size and magic immediately after any download, before parsing","Treat 0-byte downloads as fetch-layer failures (check HTTP status and content-length), not parse-time surprises"],"tags":["rvfa-format","rvfa","binary-format","input-validation"],"backgroundTag":"truncated-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"}