{"record":{"id":"fc9e2135385e9fee","repo":"heygen-com/hyperframes","slug":"build-zip-label-at-path-is-too-short-rea","errorCode":null,"errorMessage":"[build-zip] ${label} at ${path} is too short — read ${bytesRead} of ${byteCount} bytes.","messagePattern":"\\[build-zip\\] (.+?) at (.+?) is too short — read (.+?) of (.+?) bytes\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/aws-lambda/scripts/build-zip.ts","lineNumber":385,"sourceCode":"\n  const magicHex = head.subarray(0, 4).toString(\"hex\");\n  throw new Error(\n    `[build-zip] ${label} at ${path} is not a Linux x86-64 ELF executable ` +\n      `(magic=0x${magicHex}, ei_class=${head[4]}, e_machine=0x${machine.toString(16)}). ` +\n      `This usually means the deploy host's postinstall fetched a host-platform binary ` +\n      `(e.g. macOS arm64 ffmpeg) instead of the linux/x64 binary Lambda needs. ` +\n      `Re-run the build inside a linux/amd64 container, or pre-install with ` +\n      `\\`npm_config_platform=linux npm_config_arch=x64\\` so the package fetches the right binary.`,\n  );\n}\n\nfunction readFileHead(path: string, byteCount: number, label: string): Buffer {\n  const fd = openSync(path, \"r\");\n  try {\n    const buf = Buffer.alloc(byteCount);\n    const bytesRead = readSync(fd, buf, 0, byteCount, 0);\n    if (bytesRead < byteCount) {\n      throw new Error(\n        `[build-zip] ${label} at ${path} is too short — read ${bytesRead} of ${byteCount} bytes.`,\n      );\n    }\n    return buf;\n  } finally {\n    closeSync(fd);\n  }\n}\n\nfunction stageFfmpeg(stagingDir: string): void {\n  const binDir = join(stagingDir, \"bin\");\n  mkdirSync(binDir, { recursive: true });\n\n  // ffmpeg from `ffmpeg-static`. The package only ships the encoder\n  // binary; the audio pad/trim path also needs ffprobe, which comes\n  // from `ffprobe-static`.\n  //\n  // `ffmpeg-static`'s postinstall fetches a binary for the host platform","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/heygen-com/hyperframes/blob/c2996c8626135db5253519359d8a063d3bafad8d/packages/aws-lambda/scripts/build-zip.ts#L367-L403","documentation":"readFileHead opens a binary file and tries to read byteCount bytes (the ELF header size) from offset 0. If the file is smaller than the header — fewer bytes read than requested — it throws. This catches truncated or corrupt binaries before they reach the ELF validation and produce a confusing error.","triggerScenarios":"A binary file (ffmpeg, ffprobe, or chrome-headless-shell) exists on disk but is smaller than the ELF header size (~64 bytes) — a truncated download, a corrupt file, or an empty placeholder.","commonSituations":"An interrupted postinstall download left a partial file; npm cache served a corrupt artifact; a .gitignored placeholder or empty file at the expected path.","solutions":["Delete the module from node_modules and reinstall: rm -rf node_modules/ffmpeg-static && bun install.","Clear the npm cache: npm cache clean --force.","Verify the binary file size matches expectations (should be tens of MiB, not a few bytes)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { statSync } from \"node:fs\";\nfunction isHealthyBinary(path: string, minBytes = 1024): boolean {\n  try {\n    return statSync(path).size >= minBytes;\n  } catch {\n    return false;\n  }\n}\nif (!isHealthyBinary(ffmpegBinary)) {\n  console.error(`${ffmpegBinary} is missing or too small. Reinstall the package.`);\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify binary file sizes after install in CI.","Clear npm cache if downloads seem corrupt.","Use checksums where the package provides them to validate downloads."],"tags":["binary","corrupt-file","build"],"backgroundTag":null,"analyzedSha":"c2996c8626135db5253519359d8a063d3bafad8d","analyzedAt":"2026-08-12T22:18:56.877Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}