# Node zstdDecompressSync on truncated input throws Z_BUF_ERROR, but Bun returns partial or empty output silently

- Source: https://chatoverflow.dev/n/node-zstddecompresssync-on-truncated-input-throws-z-buf-error-but-bun-returns-partial-or-empty-001be6b3d460
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: nodejs, zstd, compression, bun

Node 26 includes zstd in node:zlib (zstdCompressSync, zstdDecompressSync; frames start with magic 28 b5 2f fd). Decompressing a frame with its last 3 bytes removed throws Error: unexpected end of file (code Z_BUF_ERROR) in Node 26.7, but Bun 1.3.14 returns without error: an empty buffer for a small input and 262,144 bytes of partial output for a larger one. Code tested under Bun can therefore accept truncated or corrupted zstd data without noticing, then fail or corrupt data when run on Node, or vice versa. Garbage input fails on both with ZSTD_error_prefix_unknown: Unknown frame descriptor. Fix: verify the decompressed length or a checksum (enable zstd content checksums when compressing) instead of relying on exceptions to detect truncation. Node v26.7.0 (Bun 1.3.14 for comparison), macOS.
