{"record":{"id":"8dd85ebb5e942853","repo":"ruvnet/ruflo","slug":"header-json-exceeds-maximum-size-headerlen","errorCode":null,"errorMessage":"Header JSON exceeds maximum size (${headerLen} > ${MAX_HEADER_JSON_SIZE})","messagePattern":"Header JSON exceeds maximum size \\((.+?) > (.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/appliance/rvfa-format.ts","lineNumber":332,"sourceCode":"\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);\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');","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/appliance/rvfa-format.ts#L314-L350","documentation":"Thrown by RvfaReader.fromBuffer() when the declared header JSON length (u32LE at offset 8) exceeds MAX_HEADER_JSON_SIZE (1 MiB). This is a sanity cap that rejects absurd or hostile header-length fields before attempting a multi-megabyte allocation and JSON.parse. The magic and version checks already passed.","triggerScenarios":"A corrupted 4-byte header-length field that decodes to a huge value (e.g. due to byte rotation), or a deliberately crafted malicious appliance designed to cause memory exhaustion. Random corruption of the length field commonly produces values far above 1 MiB.","commonSituations":"Bit-rot or partial overwrite of the header-length bytes; a fuzzer or adversarial input; a file produced by a buggy writer that mis-encoded the length.","solutions":["Discard the appliance file — a header length above 1 MiB is never legitimate for the current format.","Regenerate the appliance from source via RvfaBuilder.build().","If accepting untrusted appliances, keep this check as a resource-exhaustion guard.","Verify the file was not truncated or concatenated with another binary."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const MAX_HEADER = 1024 * 1024;\nfunction headerLenWithinMax(buf: Buffer): boolean {\n  if (buf.length < 12) return false;\n  const hLen = buf.readUInt32LE(8);\n  return hLen <= MAX_HEADER;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const reader = RvfaReader.fromBuffer(buf);\n} catch (e) {\n  if (/Header JSON exceeds maximum size/.test((e as Error).message)) {\n    throw new Error('Header length field is implausibly large; the appliance is corrupt or hostile');\n  }\n  throw e;\n}","preventionTips":["Treat any header length above 1 MiB as corruption; never allocate for it.","When accepting untrusted appliances, keep this cap as a DoS guard.","Regenerate appliances from source if the field is corrupt.","Do not concatenate appliances with other binaries."],"tags":["rvfa","header","validation","security"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}