{"record":{"id":"ce131978ee95f895","repo":"ruvnet/ruflo","slug":"section-sec-id-has-negative-offset-or-size","errorCode":null,"errorMessage":"Section \"${sec.id}\" has negative offset or size","messagePattern":"Section \"(.+?)\" has negative offset or size","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/appliance/rvfa-format.ts","lineNumber":358,"sourceCode":"    // 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;\n    for (const sec of header.sections) {\n      if (sec.offset < 0 || sec.size < 0) {\n        throw new Error(`Section \"${sec.id}\" has negative offset or size`);\n      }\n      if (sec.offset + sec.size > totalSize - SHA256_SIZE) {\n        throw new Error(\n          `Section \"${sec.id}\" extends beyond buffer ` +\n            `(offset=${sec.offset}, size=${sec.size}, bufLen=${totalSize})`,\n        );\n      }\n    }\n\n    // Check for overlapping sections\n    const sorted = [...header.sections].sort((a, b) => a.offset - b.offset);\n    for (let i = 1; i < sorted.length; i++) {\n      const prev = sorted[i - 1];\n      const curr = sorted[i];\n      if (prev.offset + prev.size > curr.offset) {\n        throw new Error(\n          `Sections \"${prev.id}\" and \"${curr.id}\" overlap ` +\n            `(${prev.offset}+${prev.size} > ${curr.offset})`,","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/appliance/rvfa-format.ts#L340-L376","documentation":"Thrown by RvfaReader.fromBuffer() during section bounds-checking when a section's offset or size is negative. Sections are described in the parsed header; a negative offset or size is always invalid (the buffer is addressed by unsigned subarray, so a negative value indicates corruption of the header JSON, not a legitimate small section).","triggerScenarios":"A header where one or more RvfaSection entries have offset<0 or size<0. This can only happen if the header JSON was hand-edited, corrupted, or produced by a buggy writer that left placeholder/zero-then-decrement values.","commonSituations":"A test fixture with placeholder offsets (-1) that were never resolved; bit-rot flipping a sign bit in a numeric field; a third-party writer that used -1 as a sentinel for 'empty'.","solutions":["Regenerate the appliance; offsets and sizes must be non-negative.","If writing a custom producer, ensure every section's offset and size are set to actual non-negative values before serializing.","Inspect the header JSON to find which section has the negative value.","Do not simply clamp negatives to zero — investigate the producer bug."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { validateHeader } from './rvfa-format.js';\nfunction sectionsHaveNonNegativeBounds(buf: Buffer): boolean {\n  const hLen = buf.readUInt32LE(8);\n  const parsed = JSON.parse(buf.subarray(12, 12 + hLen).toString('utf-8'));\n  if (!validateHeader(parsed)) return false;\n  return (parsed as any).sections.every((s: any) => s.offset >= 0 && s.size >= 0);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const reader = RvfaReader.fromBuffer(buf);\n} catch (e) {\n  if (/negative offset or size/.test((e as Error).message)) {\n    throw new Error('Section table contains negative offset/size; header is corrupt or hand-edited');\n  }\n  throw e;\n}","preventionTips":["Always populate section offset and size with real non-negative values before serializing.","Use RvfaWriter.build() which resolves offsets iteratively and never leaves negatives.","Never use -1 as a sentinel in section metadata.","Inspect the section table when this fires to find the offending entry."],"tags":["rvfa","section","validation","corruption"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}