{"record":{"id":"fb3348067e6e9774","repo":"denoland/deno","slug":"unexpected-end-of-data-fb3348","errorCode":null,"errorMessage":"Unexpected end of data","messagePattern":"Unexpected end of data","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"critical","filePath":"cli/rt/binary.rs","lineNumber":1244,"sourceCode":"  Ok((input, data))\n}\n\nfn read_bytes_with_u32_len(input: &[u8]) -> std::io::Result<(&[u8], &[u8])> {\n  let (input, len) = read_u32_as_usize(input)?;\n  let (input, data) = read_bytes(input, len)?;\n  Ok((input, data))\n}\n\nfn read_bytes(input: &[u8], len: usize) -> std::io::Result<(&[u8], &[u8])> {\n  check_has_len(input, len)?;\n  let (len_bytes, input) = input.split_at(len);\n  Ok((input, len_bytes))\n}\n\n#[inline(always)]\nfn check_has_len(input: &[u8], len: usize) -> std::io::Result<()> {\n  if input.len() < len {\n    Err(std::io::Error::new(\n      std::io::ErrorKind::InvalidData,\n      \"Unexpected end of data\",\n    ))\n  } else {\n    Ok(())\n  }\n}\n\nfn read_string_lossy(input: &[u8]) -> std::io::Result<(&[u8], Cow<'_, str>)> {\n  let (input, data_bytes) = read_bytes_with_u32_len(input)?;\n  Ok((input, String::from_utf8_lossy(data_bytes)))\n}\n\nfn read_u32_as_usize(input: &[u8]) -> std::io::Result<(&[u8], usize)> {\n  let (input, len_bytes) = read_bytes(input, 4)?;\n  let len = u32::from_le_bytes(len_bytes.try_into().unwrap());\n  Ok((input, len as usize))\n}","sourceCodeStart":1226,"sourceCodeEnd":1262,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/rt/binary.rs#L1226-L1262","documentation":"The denort runtime that executes `deno compile` binaries parses the embedded data section with length-prefixed reads; check_has_len() enforces that each declared length fits in the remaining bytes. Running short yields io::ErrorKind::InvalidData 'Unexpected end of data' — the binary's embedded section is truncated or its offsets are wrong, so the runtime cannot mount the virtual filesystem/modules.","triggerScenarios":"Executing a compiled binary whose data section was cut off (truncated download, interrupted docker layer, disk-full during compile); binaries modified after build (append-oriented tools) that shift the trailer the runtime locates; extreme edge: reading a file that isn't a Deno binary at all through this path.","commonSituations":"Deploying compile output through artifact stores/proxies that truncate large files; CI caching partial outputs; running a binary built where the compile step silently failed; running on a filesystem with a size limit (FAT32/email attachments) clipping the file.","solutions":["Re-run `deno compile` on the build machine and execute the output there to confirm it works before distribution","Compare byte size and sha256 of the binary at build vs deploy locations; any difference means re-transfer","Free disk space / check CI logs for a failed or partially-written compile step","Do not append to or re-pack compiled binaries; if you must wrap them, ship the original bytes intact inside the wrapper"],"exampleFix":"# before\n./app  # Unexpected end of data\nls -l app   # 12 MB, but build log says 18 MB -> truncated\n\n# after\ndeno compile -o app src/mod.ts   # full rebuild\nsha256sum app  # verify matches on every hop; then ./app","handlingStrategy":"validation","validationCode":"// Validate the compiled binary before first run in deployment scripts\nconst st = await Deno.stat(appPath);\nif (build.size && st.size !== build.size) {\n  throw new Error(`${appPath}: ${st.size} bytes on disk, ${build.size} expected — truncated transfer`);\n}","typeGuard":null,"tryCatchPattern":"const { code, stderr } = await new Deno.Command(appPath).output();\nconst err = new TextDecoder().decode(stderr);\nif (code !== 0 && err.includes(\"Unexpected end of data\")) {\n  // binary's embedded section is truncated: re-download from CI, verify sha256, re-run\n  throw new Error(\"compiled binary is truncated; redeploy from a verified artifact\");\n}","preventionTips":["Always checksum compiled artifacts between build and deploy","Watch for disk-full during deno compile (check exit code and stderr)","Avoid file-transfer channels with size limits (email, FAT32 media) for compiled binaries"],"tags":["standalone-binary","denort","truncated-data","deserialization","virtual-filesystem"],"backgroundTag":"truncated-binary-data","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}