{"record":{"id":"d0732cfb08b162e8","repo":"oven-sh/bun","slug":"invalid-gzip-data","errorCode":null,"errorMessage":"Invalid gzip data","messagePattern":"Invalid gzip data","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bun-release/src/npm/install.ts","lineNumber":100,"sourceCode":"    }\n  } finally {\n    try {\n      rm(cwd);\n    } catch (error) {\n      debug(\"rm failed\", error);\n      // There is nothing to do if the directory cannot be cleaned up.\n    }\n  }\n}\n\nasync function downloadBun(platform: Platform, dst: string): Promise<void> {\n  const response = await fetch(`https://registry.npmjs.org/${owner}/${platform.bin}/-/${platform.bin}-${version}.tgz`);\n  const tgz = await response.arrayBuffer();\n  let buffer: Buffer;\n  try {\n    buffer = unzipSync(tgz);\n  } catch (cause) {\n    throw new Error(\"Invalid gzip data\", { cause });\n  }\n  function str(i: number, n: number): string {\n    return String.fromCharCode(...buffer.subarray(i, i + n)).replace(/\\0.*$/, \"\");\n  }\n  let offset = 0;\n  while (offset < buffer.length) {\n    const name = str(offset, 100).replace(\"package/\", \"\");\n    const size = parseInt(str(offset + 124, 12), 8);\n    offset += 512;\n    if (!isNaN(size)) {\n      const entryPath = join(dst, name);\n      const entryName = relative(dst, entryPath);\n      if (entryName && !entryName.startsWith(\"..\") && !isAbsolute(entryName)) {\n        write(entryPath, buffer.subarray(offset, offset + size));\n        if (name === platform.exe) {\n          try {\n            chmod(entryPath, 0o755);\n          } catch (error) {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/packages/bun-release/src/npm/install.ts#L82-L118","documentation":"downloadBun() fetches the platform tarball from registry.npmjs.org and decompresses it with unzipSync; if decompression throws, the error is wrapped as 'Invalid gzip data' with the underlying cause attached. In practice the bytes were not a valid gzip/tgz stream: a truncated download, an HTML error page saved as the body, or a tarball altered in transit.","triggerScenarios":"A proxy or registry mirror returning 200 with an HTML error page; a truncated response on a flaky connection; disk-full producing a short file; MITM/antivirus rewriting the archive.","commonSituations":"Self-hosted npm registries serving cached/corrupted artifacts; CI networks with aggressive inspection; intermittent connections during postinstall downloads.","solutions":["Retry the install after clearing cache (npm cache clean --force, remove node_modules)","Verify the tarball manually: download the URL and run 'tar -tzf' on it — if it is HTML, fix the registry/proxy","Check the HTTP status before trusting the body and bypass the offending proxy for registry.npmjs.org","Use the standalone install script which downloads from bun.com instead"],"exampleFix":"// before\nconst tgz = await (await fetch(url)).arrayBuffer();\nconst buf = unzipSync(tgz);\n\n// after\nconst res = await fetch(url);\nif (!res.ok) throw new Error(`registry responded ${res.status}`);\nconst tgz = Buffer.from(await res.arrayBuffer());\nif (tgz[0] !== 0x1f || tgz[1] !== 0x8b) throw new Error('not a gzip stream');\nconst buf = unzipSync(tgz);","handlingStrategy":"retry","validationCode":"const tgz = Buffer.from(await res.arrayBuffer());\nconst isGzip = tgz.length > 2 && tgz[0] === 0x1f && tgz[1] === 0x8b;\nif (!res.ok || !isGzip) throw new Error('tarball is not gzip — registry/proxy problem');","typeGuard":null,"tryCatchPattern":"try {\n  buffer = unzipSync(tgz);\n} catch (cause) {\n  throw new Error('Invalid gzip data', { cause }); // keep the cause for diagnosis; retry the download\n}","preventionTips":["Check res.ok and gzip magic bytes before decompressing downloaded archives","Pin a trustworthy registry endpoint; bypass MITM proxies for registry.npmjs.org when archives get altered","Clear caches when retrying so a corrupted cached artifact is not reused"],"tags":["npm","install","gzip","network"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}