{"record":{"id":"2048148d6c7d0122","repo":"ruvnet/ruflo","slug":"buffer-too-small-to-contain-declared-header","errorCode":null,"errorMessage":"Buffer too small to contain declared header","messagePattern":"Buffer too small to contain declared header","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/appliance/rvfa-format.ts","lineNumber":337,"sourceCode":"    }\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);\n    if (headerLen > MAX_HEADER_JSON_SIZE) {\n      throw new Error(\n        `Header JSON exceeds maximum size (${headerLen} > ${MAX_HEADER_JSON_SIZE})`,\n      );\n    }\n    if (PREAMBLE_SIZE + headerLen > buf.length) {\n      throw new Error('Buffer too small to contain declared header');\n    }\n\n    // Parse header JSON\n    const headerSlice = buf.subarray(PREAMBLE_SIZE, PREAMBLE_SIZE + headerLen);\n    let parsed: unknown;\n    try {\n      parsed = JSON.parse(headerSlice.toString('utf-8'));\n    } catch {\n      throw new Error('Failed to parse RVFA header JSON');\n    }\n\n    if (!validateHeader(parsed)) {\n      throw new Error('RVFA header failed validation');\n    }\n    const header = parsed as RvfaHeader;\n\n    // Bounds-check every section offset\n    const totalSize = buf.length;","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/appliance/rvfa-format.ts#L319-L355","documentation":"Thrown by RvfaReader.fromBuffer() when PREAMBLE_SIZE(12) + declared header length exceeds the actual buffer length. Unlike error 133 (which rejects oversized headers outright), this fires for a header length that is plausible (<1 MiB) but still larger than what the buffer contains — i.e. a truncated header region.","triggerScenarios":"The appliance file was truncated mid-header (e.g. interrupted write or download), or the header-length field is correct but the body is missing bytes. Magic and version already passed; the length is under 1 MiB.","commonSituations":"A killed build process left a partial .rvfa; IPFS fetch was cut short; a copy operation hit disk-full; a proxy truncated the body.","solutions":["Re-fetch or rebuild the appliance; the header region is incomplete.","Compare file size against the producer's reported size.","If you control the producer, emit a sidecar size manifest for round-trip validation.","Reject files whose preamble-length plus header exceeds remaining bytes before parsing."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const RVFA_PRE = 12;\nfunction headerFitsInBuffer(buf: Buffer): boolean {\n  if (buf.length < RVFA_PRE) return false;\n  const hLen = buf.readUInt32LE(8);\n  return hLen <= 1024 * 1024 && RVFA_PRE + hLen <= buf.length;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const reader = RvfaReader.fromBuffer(buf);\n} catch (e) {\n  if (/Buffer too small to contain declared header/.test((e as Error).message)) {\n    throw new Error('RVFA header region is truncated; re-download or rebuild the appliance');\n  }\n  throw e;\n}","preventionTips":["Compare the downloaded file size against the producer's manifest.","Use content-addressed storage so truncation is detectable via CID mismatch.","Write appliances atomically (tmp + rename) to avoid partial files.","Run reader.verify() on received appliances before use."],"tags":["rvfa","buffer","truncation","binary-format"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}