{"record":{"id":"bedb85984a2cfa2f","repo":"ruvnet/ruflo","slug":"invalid-rvfp-magic-magic","errorCode":null,"errorMessage":"Invalid RVFP magic: \"${magic}\"","messagePattern":"Invalid RVFP magic: \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/appliance/rvfa-distribution.ts","lineNumber":193,"sourceCode":"      created: new Date().toISOString(), newSectionSize: payload.length,\n      newSectionSha256: sha256(payload), compression: comp,\n    };\n    if (opts.privateKey && opts.signedBy) {\n      const signable = Buffer.concat([Buffer.from(canonicalJson(header), 'utf-8'), payload]);\n      header.signature = edSign(signable, opts.privateKey);\n      header.signedBy = opts.signedBy;\n    }\n    const hJson = Buffer.from(JSON.stringify(header), 'utf-8');\n    const magic = Buffer.from('RVFP');\n    const ver = Buffer.alloc(4); ver.writeUInt32LE(RVFP_VERSION, 0);\n    const hLen = Buffer.alloc(4); hLen.writeUInt32LE(hJson.length, 0);\n    return Buffer.concat([magic, ver, hLen, hJson, payload, sha256B(payload)]);\n  }\n\n  static parsePatchHeader(buf: Buffer): RvfpHeader {\n    if (buf.length < PRE) throw new Error('Buffer too small for RVFP preamble');\n    const magic = buf.subarray(0, 4).toString('ascii');\n    if (magic !== 'RVFP') throw new Error(`Invalid RVFP magic: \"${magic}\"`);\n    const ver = buf.readUInt32LE(4);\n    if (ver !== RVFP_VERSION) throw new Error(`Unsupported RVFP version: ${ver}`);\n    const hLen = buf.readUInt32LE(8);\n    if (PRE + hLen > buf.length) throw new Error('Buffer too small for declared header');\n    const h = JSON.parse(buf.subarray(PRE, PRE + hLen).toString('utf-8')) as RvfpHeader;\n    if (h.magic !== 'RVFP') throw new Error('RVFP header magic mismatch');\n    return h;\n  }\n\n  static async verifyPatch(buf: Buffer): Promise<PatchVerifyResult> {\n    const errors: string[] = [];\n    let header: RvfpHeader;\n    try { header = RvfaPatcher.parsePatchHeader(buf); } catch (e) {\n      const empty: RvfpHeader = {\n        magic: 'RVFP', version: 0, targetApplianceName: '', targetApplianceVersion: '',\n        targetSection: '', patchVersion: '', created: '', newSectionSize: 0,\n        newSectionSha256: '', compression: 'none',\n      };","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/appliance/rvfa-distribution.ts#L175-L211","documentation":"Thrown by parsePatchHeader() when the first 4 bytes of the buffer are not the ASCII string \"RVFP\". The buffer is long enough to pass the preamble-size check, but its magic bytes identify it as something other than an RVFP patch. This is the format-identity guard that runs after the length check and before the version check.","triggerScenarios":"Passing a non-patch buffer (e.g. an RVFA appliance, a gzip stream, a JSON document, or random bytes) to parsePatchHeader/applyPatch/verifyPatch. The first 4 bytes happen not to be 0x52 0x56 0x46 0x50 ('R','V','F','P').","commonSituations":"Swapping a .rvfa appliance file for a .rvfp patch file in a deploy pipeline; feeding a gzipped patch without first gunzipping; reading a file that was overwritten by a different tool.","solutions":["Confirm the input is an RVFP patch produced by RvfaPatcher.createPatch().","If the file is gzipped on disk, gunzip it to a Buffer before parsing.","Validate the magic bytes (buf.subarray(0,4).equals(Buffer.from('RVFP'))) before calling.","Re-download or regenerate the patch if the file content is wrong."],"exampleFix":"// before\nconst header = RvfaPatcher.parsePatchHeader(buf);\n\n// after\nif (buf.subarray(0, 4).toString('ascii') !== 'RVFP') {\n  throw new Error('Input is not an RVFP patch (bad magic)');\n}\nconst header = RvfaPatcher.parsePatchHeader(buf);","handlingStrategy":"validation","validationCode":"function hasRvfpMagic(buf: Buffer): boolean {\n  return buf.length >= 4 && buf.subarray(0, 4).toString('ascii') === 'RVFP';\n}","typeGuard":"function isRvfpBuffer(buf: unknown): buf is Buffer {\n  return Buffer.isBuffer(buf) && buf.length >= 4 && buf.subarray(0, 4).toString('ascii') === 'RVFP';\n}","tryCatchPattern":"try {\n  const header = RvfaPatcher.parsePatchHeader(buf);\n} catch (e) {\n  if (/Invalid RVFP magic/.test((e as Error).message)) {\n    throw new Error('Input is not an RVFP patch; check that you passed a .rvfp, not a .rvfa');\n  }\n  throw e;\n}","preventionTips":["Check the first 4 bytes equal 'RVFP' before calling parsePatchHeader.","Keep RVFA appliance and RVFP patch handling in distinct code paths.","Gunzip any gzipped patch transport before parsing.","Name files with .rvfp extension and validate the extension in pipelines."],"tags":["rvfp","binary-format","magic","validation"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}