{"record":{"id":"8c067056857ec393","repo":"denoland/deno","slug":"unexpected-end-of-data","errorCode":null,"errorMessage":"Unexpected end of data","messagePattern":"Unexpected end of data","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"critical","filePath":"cli/lib/standalone/binary.rs","lineNumber":423,"sourceCode":"  let len = u32::from_le_bytes(len_bytes.try_into().unwrap());\n  Ok((input, len))\n}\n\nfn read_u8(input: &[u8]) -> std::io::Result<(&[u8], u8)> {\n  check_has_len(input, 1)?;\n  Ok((&input[1..], input[0]))\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","sourceCodeStart":405,"sourceCodeEnd":431,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/lib/standalone/binary.rs#L405-L431","documentation":"Parsing a deno compile binary's trailing metadata uses length-prefixed byte reads guarded by check_has_len(): every read demands that `len` bytes remain in the input. When the remaining slice is shorter than the declared length, parsing stops with io::ErrorKind::InvalidData 'Unexpected end of data' — the metadata section is truncated relative to its own length fields.","triggerScenarios":"A compiled binary truncated by a failed write (disk full, killed process) or partial transfer, so the trailer's declared section lengths exceed the actual bytes; a binary whose bytes were appended-to/repacked with wrong offsets; version-skewed writers emitting lengths a reader interprets differently.","commonSituations":"`deno compile` output copied with cp/rsync interrupted; docker COPY of a still-being-written file; CI artifact upload truncated; binaries sent over channels that strip trailing bytes (rare) or modified by post-processing tools (upx, signtool) that break Deno's trailer layout.","solutions":["Rebuild the binary from source with an unchanged toolchain and verify it runs on the build machine before shipping","Compare file sizes/checksums between build and deploy locations to detect truncation","Avoid post-processing compiled binaries with packers/signers that rewrite the file layout; Deno's trailer must remain intact","Ensure the compile process fully succeeds (exit code 0, no disk-full errors) before distributing"],"exampleFix":"# before\n# artifact truncated in transfer\ndeno run ./app  # Unexpected end of data\n\n# after\n# rebuild and verify checksum end-to-end\ndeno compile -o app src/mod.ts && sha256sum app\nscp app host:&& ssh host sha256sum app  # must match; then run","handlingStrategy":"validation","validationCode":"// Refuse to parse obviously-truncated artifacts\nconst EXPECTED_MIN = 1024; // whatever your pipeline records at build time\nconst st = await Deno.stat(binaryPath);\nif (st.size < EXPECTED_MIN) throw new Error(`Binary looks truncated: ${st.size} < ${EXPECTED_MIN}`);\nconst bytes = await Deno.readFile(binaryPath);\nif (bytes.at(-1) === undefined || bytes.length === 0) throw new Error(\"empty binary\");","typeGuard":null,"tryCatchPattern":"// Rust: parse the standalone trailer defensively\nmatch parse_binary_trailer(&bytes) {\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidData && e.to_string().contains(\"Unexpected end of data\") => {\n        // re-download/rebuild; parsing again on the same bytes cannot succeed\n        Err(anyhow!(\"compiled binary truncated; expected {} bytes\", expected_len))\n    }\n    r => r.map_err(Into::into),\n}","preventionTips":["Verify sha256 of compiled binaries at every transfer hop","Never post-process binaries with tools that rewrite layout (upx, signers) unless Deno documents support","Ensure compile steps complete with exit 0 before archiving outputs"],"tags":["standalone-binary","compile","truncated-data","deserialization","corruption"],"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"}