{"record":{"id":"97b117995546a766","repo":"Hmbown/CodeWhale","slug":"invalid-update-archive-length","errorCode":null,"errorMessage":"Invalid update archive length.","messagePattern":"Invalid update archive length\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/tui/plugins/computer-use/app/updates.mjs","lineNumber":80,"sourceCode":"    const size=bytes.readUInt32LE(position+24); total+=size;\n    if(flags&1||![0,8].includes(method)||![0,0x4000,0x8000].includes(kind)||total>512*1024*1024||position+46+length+extra+comment>end) throw new Error(\"Unsupported update entry.\");\n    if(!name.startsWith(`${APP_NAME}.app/`)||name.includes(\"\\\\\")||name.includes(\":\")||name.includes(\"\\0\")||name.split(\"/\").some(part=>part===\"..\"||part===\".\")||seen.has(name)) throw new Error(\"Unsafe update path.\");\n    seen.add(name);\n    if(offset+30>position||bytes.readUInt32LE(offset)!==0x04034b50) throw new Error(\"Invalid update file header.\");\n    const localLength=bytes.readUInt16LE(offset+26),localExtra=bytes.readUInt16LE(offset+28);\n    if(offset+30+localLength+localExtra+compressed>bytes.readUInt32LE(end+16)||bytes.subarray(offset+30,offset+30+localLength).toString(\"utf8\")!==name) throw new Error(\"Inconsistent update file header.\");\n    if(bytes.readUInt16LE(offset+8)!==method||bytes.readUInt16LE(offset+6)!==flags||(!(flags&8)&&(bytes.readUInt32LE(offset+18)!==compressed||bytes.readUInt32LE(offset+22)!==size))) throw new Error(\"Inconsistent update sizes or compression.\");\n    const start=offset+30+localLength+localExtra;\n    // Header sizes are untrusted. Bound actual expansion before ditto writes\n    // anything, including a compressed payload whose headers understate size.\n    const payload=bytes.subarray(start,start+compressed);\n    let expanded;\n    try { expanded=method===0?payload.length:inflateRawSync(payload,{maxOutputLength:Math.max(size,1)}).length; }\n    catch { throw new Error(\"Invalid or oversized compressed update entry.\"); }\n    if(expanded!==size) throw new Error(\"The update entry size did not match its contents.\");\n    position+=46+length+extra+comment;\n  }\n  if(position!==end) throw new Error(\"Invalid update archive length.\");\n  return count;\n}\n\nexport async function prepareUpdate(update) {\n  if(!update?.available) throw new Error(\"Check for an available update first.\");\n  if(!newerVersion(update.version,APP_VERSION)||update.url!==`${repository}/releases/download/v${update.version}/Codewhale-Computer-Use-${update.version}-macos-universal.zip`||!Number.isSafeInteger(update.size)||update.size<=0||update.size>limit) throw new Error(\"The update identity is invalid.\");\n  // Only GitHub's fixed release URL and its asset CDN can serve the bytes.\n  let url=update.url, response;\n  for(let redirects=0;redirects<4;redirects++) {\n    response=await fetch(url,{redirect:\"manual\",signal:AbortSignal.timeout(60_000)});\n    if(![301,302,303,307,308].includes(response.status)) break;\n    const next=new URL(response.headers.get(\"location\"),url);\n    if(next.protocol!==\"https:\"||![\"github.com\",\"release-assets.githubusercontent.com\",\"objects.githubusercontent.com\"].includes(next.hostname)) throw new Error(\"The update download redirected to an unexpected host.\");\n    url=next.href;\n  }\n  if(!response?.ok) throw new Error(\"The update could not be downloaded. Your current app is unchanged.\");\n  const bytes=await responseBytes(response,update.size);\n  if(bytes.length!==update.size||crypto.createHash(\"sha256\").update(bytes).digest(\"hex\")!==update.sha256) throw new Error(\"The update checksum did not match. Your current app is unchanged.\");","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/plugins/computer-use/app/updates.mjs#L62-L98","documentation":"After processing all `count` central-directory entries, the validator requires the cursor to land exactly on the start of the end-of-central-directory record (`position===end`). Leftover unaccounted bytes between the last central-directory entry and the EOCD mean the index declared fewer/differently-sized entries than the archive contains — the archive structure doesn't reconcile, so it's rejected.","triggerScenarios":"An EOCD whose entry count (at end+10) or central-directory size (at end+12) doesn't match the actual entries walked — e.g. extra bytes appended before the EOCD, a prepended self-extracting stub, or an archive where entries were removed but the count/size fields weren't updated.","commonSituations":"Concatenating or stripping entries from a zip with a hex editor or script without rewriting the EOCD; prepending an SFX stub to a prebuilt zip; a zip writer bug emitting padding before the EOCD; tampered update payloads.","solutions":["Rebuild the archive with a standard tool (`ditto -c -k` or `zip -r`) so EOCD count/size are computed by the writer.","Do not prepend SFX stubs or append signatures inside the central-directory span; if a stub is required, it must be handled outside this validator's contract.","Run `zipinfo` or `unzip -t` to confirm the archive reconciles before uploading.","Verify the downloaded asset's SHA-256 to detect transfer corruption or tampering."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const tail = bytes.subarray(Math.max(0,bytes.length-64)).toString(\"latin1\");\nif (!tail.includes(\"PK\\x05\\x06\")) throw new Error(\"No EOCD at end\");","typeGuard":null,"tryCatchPattern":"try { validateReleaseZip(bytes); } catch (e) { if (e.message === \"Invalid update archive length.\") throw new Error(\"EOCD count/size don't reconcile — rebuild the archive\"); throw e; }","preventionTips":["Let the zip writer compute EOCD fields; never edit them","Don't concatenate, strip, or stub-augment release zips","Run `zipinfo` before upload","Verify asset digest on download"],"tags":["zip","archive-parsing","corrupt-file","update-integrity"],"backgroundTag":"unexpected-response-shape","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}