{"record":{"id":"f4e2f4c84bcd79d7","repo":"Hmbown/CodeWhale","slug":"the-update-entry-size-did-not-match-its-contents","errorCode":null,"errorMessage":"The update entry size did not match its contents.","messagePattern":"The update entry size did not match its contents\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/tui/plugins/computer-use/app/updates.mjs","lineNumber":77,"sourceCode":"    const flags=bytes.readUInt16LE(position+8),method=bytes.readUInt16LE(position+10),length=bytes.readUInt16LE(position+28),extra=bytes.readUInt16LE(position+30),comment=bytes.readUInt16LE(position+32);\n    const name=bytes.subarray(position+46,position+46+length).toString(\"utf8\");\n    const kind=(bytes.readUInt32LE(position+38)>>>16)&0xf000,offset=bytes.readUInt32LE(position+42),compressed=bytes.readUInt32LE(position+20);\n    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  }","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/plugins/computer-use/app/updates.mjs#L59-L95","documentation":"After successfully inflating an entry, the validator compares the actual expanded byte count with the size declared in the central directory (`expanded!==size`). A mismatch means the archive's declared metadata doesn't describe its real content, so downstream layout math and the extraction step would operate on wrong sizes — treated as integrity failure and rejected.","triggerScenarios":"An entry whose deflate stream decodes to a byte count different from the central-directory `size` field — e.g. sizes written for a pre-compression variant of the file, an archive edited after creation, or stored (method 0) entries whose payload length differs from the declared size.","commonSituations":"Build scripts patching file contents inside a finished zip without updating the central directory; tools writing data descriptors while central sizes were copied from a template; tampered or maliciously crafted updates; partial re-zipping of an artifact.","solutions":["Rebuild the archive from source with a standard zip tool; never patch entries inside an existing zip.","Verify with `unzip -t` (CRC check catches the same inconsistency) before publishing.","Re-download and SHA-256-verify the asset to rule out a corrupt transfer.","Ensure the packaging pipeline writes sizes last (after content is final) — regenerate the zip whenever any entry content changes."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"execFileSync(\"unzip\", [\"-t\", zipPath], {stdio:\"inherit\"});","typeGuard":null,"tryCatchPattern":"try { validateReleaseZip(bytes); } catch (e) { if (e.message === \"The update entry size did not match its contents.\") throw new Error(\"Declared size ≠ inflated size — rebuild the artifact\"); throw e; }","preventionTips":["Never patch file contents inside an existing zip","Regenerate the archive whenever any entry changes","CRC-check with `unzip -t` in the release pipeline","SHA-256-verify the downloaded asset"],"tags":["zip","archive-parsing","size-mismatch","corrupt-file","update-integrity"],"backgroundTag":"checksum-mismatch","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"}